All fields on the page (For Example, text box, radio options, drop-down lists) should be aligned properly.
Language: Java
Framework: Selenium 4
1//Assuming the web page is loaded correctly2//Connecting to local driver3WebDriver driver = new ChromeDriver();45//Navigate to the webpage6driver.get("https://example.com");78//Identifying all the web elements using css selector9List<WebElement> webElements = driver.findElements(By.cssSelector("*"));1011//Iterating through the web elements to check their alignment12for(WebElement element: webElements){13 String elementLocation = element.getCssValue("text-align");14 if(!elementLocation.equals("left") && !elementLocation.equals("center") && !elementLocation.equals("right")){15 System.out.println("Field alignment issue detected!");16 }17}1819//Disconnecting the local driver20driver.quit();2122//Connecting to remote client with desired capabilities23WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.chrome());2425//Rest of the code remains the same
Language: Python
Framework: Selenium 4
1# Assumptions:2# - The page to be tested has fields including text boxes, radio options, and drop-down lists3# - The HTML elements for these fields have the same class name4# - The expected alignment is left-aligned56from selenium.webdriver import Chrome, ChromeOptions7from selenium.webdriver.common.by import By8from selenium.webdriver.support.ui import WebDriverWait9from selenium.webdriver.support import expected_conditions as EC1011# Create a local Chrome driver12options = ChromeOptions()13driver = Chrome(options=options)1415# Connect to a remote driver with desired capabilities16# options = ChromeOptions()17# options.add_argument('platform=WINDOWS')18# options.add_argument('version=10')19# options.add_argument('screenResolution=1920x1080')20# driver = webdriver.Remote(21# command_executor='{remote_address}/wd/hub',22# desired_capabilities=options.to_capabilities())2324# Load the webpage to be tested25driver.get('http://example.com')2627# Wait for all fields to be visible28fields = WebDriverWait(driver, 10).until(29 EC.visibility_of_all_elements_located((By.CLASS_NAME, 'field'))30)3132# Check if all fields are left-aligned33for field in fields:34 if field.value_of_css_property('text-align') != 'left':35 assert False, f"Field {field.get_attribute('name')} is not left-aligned"3637# Close the browser window38driver.quit()
Language: Javascript
Framework: Cypress
1//Assuming the application is a web app with multiple forms and input fields2//Assuming that the page we are testing is already loaded34describe('General webpage functionality', () => {5 it('Test field alignment', () => {6 cy.get('form') //assumming all fields are in a form7 .should('have.css', 'display', 'flex') //assuming fields are displayed in a flexbox8 .and('have.css', 'flex-direction', 'column') //assuming fields are displayed in a column9 .and('have.css', 'align-items', 'center'); //assuming fields are aligned in the center of the column10 });11});12//To connect to remote client with desired capabilities, we can add the following code1314const browserName = 'chrome'; //assuming we're using Chrome as the browser15const platformName = 'Windows 10'; //assuming we're using Windows 10 as the platform1617describe('General webpage functionality', () => {18 beforeEach(() => {19 cy.visit('', { //assuming we have a url to visit20 browserName,21 platformName22 });23 });2425 it('Test field alignment', () => {26 cy.get('form')27 .should('have.css', 'display', 'flex')28 .and('have.css', 'flex-direction', 'column')29 .and('have.css', 'align-items', 'center');30 });31});
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