When components are repeated across web pages, they should appear in the same relative order with regard to other repeated components on each web page where they appear.
Language: Java
Framework: Selenium 4
1Assumptions: 21. The web pages are dynamically generated and the order of components cannot be predicted beforehand.32. The test will be executed locally on a Windows machine with Chrome driver installed.43. The web pages have been tested for basic functionality and are fully loaded when the test is executed.56import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.chrome.ChromeDriver;1011public class AccessibilityTesting {1213 public static void main(String[] args){14 //Set Chrome driver path15 System.setProperty("webdriver.chrome.driver","path to chrome driver");1617 //Create Chrome driver object18 WebDriver driver=new ChromeDriver();19 20 //Navigate to first web page21 driver.get("https://example.com/page1");22 23 //Find all the components and store them in a list24 List<WebElement> componentsPage1= driver.findElements(By.xpath("//div[@class='component']"));25 26 //Navigate to second web page27 driver.get("https://example.com/page2");28 29 //Find all the components and store them in a list30 List<WebElement> componentsPage2= driver.findElements(By.xpath("//div[@class='component']"));31 32 //Compare the order of components in both the web pages33 boolean isOrderSame=true;34 for(int i=0;i<componentsPage1.size();i++){35 String componentTextPage1=componentsPage1.get(i).getText();36 String componentTextPage2=componentsPage2.get(i).getText();37 38 if(!componentTextPage1.equals(componentTextPage2)){39 isOrderSame=false;40 break;41 }42 }43 44 //Print the result45 if(isOrderSame){46 System.out.println("Test Passed: Consistent component order across pages");47 }48 else{49 System.out.println("Test Failed: Inconsistent component order across pages");50 }51 52 //Close the browser53 driver.quit();54 }55 56 /*57 * Code to connect to remote client with desired capabilities58 59 DesiredCapabilities capabilities = new DesiredCapabilities();60 capabilities.setBrowserName("chrome");61 capabilities.setVersion("91.0");6263 RemoteWebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:8888/wd/hub"), capabilities);64 */65}
Language: Python
Framework: Selenium 4
1from selenium import webdriver23# Assuming the website to be tested is already open on the browser4driver = webdriver.Chrome()56# Connecting to remote client with desired capabilities7# Uncomment the desired capabilities code to connect to remote server89# Set desired capabilities 10# desired_cap = {11# 'browserName': 'chrome',12# 'version': '91.0',13# 'platform': 'WINDOWS',14# 'name': 'Accessibility testing'15# }1617# Connect to remote client with desired capabilities18# driver = webdriver.Remote(19# command_executor='http://localhost:4444/wd/hub',20# desired_capabilities=desired_cap21# )2223# Check component order across pages24component_list = [] # list to hold components on each page25page_count = 0 # number of pages tested2627# Browse through each web page28for page in list_of_pages:29 page_count += 1 # increment number of pages tested3031 # Locate and append components on current web page to component list32 components = driver.find_elements_by_xpath("//div[@class='component']")33 for component in components:34 component_list.append(component.get_attribute("id"))3536 # For the second page and above, compare current component list with previous page37 if page_count > 1: 38 for i in range(0, len(component_list)):39 if component_list[i] != previous_component_list[i]:40 print("Component order inconsistent on page", page_count)41 break42 # Set current component list as previous component list for next page43 previous_component_list = component_list.copy()44 component_list.clear()4546# Close the browser47driver.quit()
Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing