Accessibility testing : Responsive stylesheets for 320px width

Provide responsive stylesheets such that content can be displayed at 320px wide without horizontal scrolling. (Content which must be displayed in two dimensions, such as maps and data tables, may have horizontal scrolling.)

Language: Java

Framework: Selenium 4

copy
1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.chrome.ChromeDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import org.openqa.selenium.remote.DesiredCapabilities;56public class AccessibilityTesting {7 8 public static void main(String[] args) {9 10 /​/​ Assumptions: The website to be tested is already loaded on the browser.11 /​/​ The website has responsive stylesheets implemented.12 13 /​/​ Set the path to the local Chrome driver executable14 System.setProperty("webdriver.chrome.driver", "/​path/​to/​chromedriver");15 16 /​/​ Create an instance of the ChromeOptions class17 ChromeOptions options = new ChromeOptions();18 19 /​/​ Add the "--start-maximized" flag to maximize the browser window20 options.addArguments("--start-maximized");21 22 /​/​ Create an instance of the DesiredCapabilities class and pass the ChromeOptions object23 DesiredCapabilities capabilities = DesiredCapabilities.chrome();24 capabilities.setCapability(ChromeOptions.CAPABILITY, options);25 26 /​/​ Uncomment the following code to connect to a remote client with desired capabilities27 /​/​capabilities.setBrowserName("chrome");28 /​/​capabilities.setVersion("latest");29 /​/​capabilities.setCapability("enableVNC", true);30 /​/​capabilities.setCapability("enableVideo", false);31 /​/​capabilities.setCapability("name", "Accessibility Testing");32 /​/​capabilities.setCapability("screenResolution", "1366x768");33 /​/​capabilities.setCapability("tz", "Europe/​London");34 /​/​capabilities.setCapability("selenoid:options", Map.of("enableVNC", true));35 36 /​/​ Create an instance of the ChromeDriver class and pass the DesiredCapabilities object37 WebDriver driver = new ChromeDriver(capabilities);38 39 /​/​ Navigate to the website to be tested40 driver.get("https:/​/​www.example.com/​");41 42 /​/​ Set the browser window size to 320px wide43 driver.manage().window().setSize(new Dimension(320, 568));44 45 /​/​ Check if the content is displayed without horizontal scrolling46 boolean isResponsive = (boolean) ((JavascriptExecutor) driver).executeScript("return (document.body.scrollWidth <= document.documentElement.clientWidth)");47 48 if (isResponsive) {49 System.out.println("Responsive stylesheets are working as expected!");50 } else {51 System.out.println("Content can't be displayed at 320px wide without horizontal scrolling.");52 }53 54 /​/​ Close the browser55 driver.quit();56 }57}

Language: Python

Framework: Selenium 4

copy
1# Assumptions: 2# 1. The website being tested has responsive stylesheets that can adjust to different screen sizes.3# 2. The website is accessible and no login or authentication is required.4# 3. The test will be run on Google Chrome browser with a local driver installed.56# Importing the necessary libraries7from selenium.webdriver import Chrome8from selenium.webdriver.common.keys import Keys9from selenium.webdriver.chrome.options import Options1011# Setting up the local driver12chrome_options = Options()13chrome_options.add_argument("--disable-extensions")14chrome_options.add_argument("--headless")15chrome_driver_path = "path/​to/​chrome/​driver"16driver = Chrome(executable_path=chrome_driver_path, options=chrome_options)1718# Connecting to remote client with desired capabilities19# Desired capabilities can be added as arguments to the options object in the local driver setup2021# Navigating to the website being tested22url = "https:/​/​www.example.com"23driver.get(url)2425# Maximizing the window to simulate a 320px wide screen26driver.maximize_window()2728# Checking if there is horizontal scrolling29width = driver.execute_script("return document.body.scrollWidth")30height = driver.execute_script("return document.body.scrollHeight")31if driver.execute_script("return window.innerWidth") < width:32 print("Horizontal scrolling exists")33else:34 print("No horizontal scrolling")3536# Closing the browser window37driver.close()

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.

Accelerate Your Automation Test Cycles With LambdaTest

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.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing