Accessibility testing : Orientation-independent content and functionality

All content and functionality should be available regardless of whether a mobile device is oriented vertically or horizontally, unless the orientation of the device is absolutely essential.

Language: Java

Framework: Selenium 4

copy
1/​/​Assuming that the website under test has responsive design to adapt to screen orientations2/​/​Assuming that the website is built using HTML, CSS and JS and does not require any other web technologies to function34import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebDriver;89public class AccessibilityTesting {1011 public static void main(String[] args) {1213 /​/​Initialize Chrome Driver14 System.setProperty("webdriver.chrome.driver", "path/​to/​chromedriver");15 WebDriver driver = new ChromeDriver();1617 /​/​Navigate to website under test18 driver.get("http:/​/​www.example.com");1920 /​/​Maximize window to ensure content fits in screen regardless of orientation21 driver.manage().window().maximize();2223 /​/​Get orientation of device24 String orientation = driver.executeScript("return window.screen.orientation.type").toString();2526 /​/​If device orientation is landscape, change to portrait for testing27 if (orientation.equals("landscape-primary") || orientation.equals("landscape-secondary")) {28 driver.executeScript("return screen.orientation.lock('portrait')");29 }3031 /​/​Perform testing on content and functionality in both portrait and landscape orientation32 /​/​Assert that all content and functionality remains available in both orientations3334 /​/​If necessary, revert device orientation to original state35 driver.executeScript("return screen.orientation.unlock()");3637 /​/​Close WebDriver instance38 driver.quit();394041 /​/​Code to connect to remote client with desired capabilities42 /​*43 DesiredCapabilities capability = new DesiredCapabilities();44 capability.setBrowserName("chrome");45 WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capability);46 */​47 48 }4950}

Language: Python

Framework: Selenium 4

copy
1from selenium.webdriver import Chrome2from selenium.webdriver.chrome.options import Options34#Assuming that the web application is responsive to device orientation5#Assuming that the webpage can be opened on a mobile device6#Assuming that the ChromeDriver is installed locally78#Local driver9driverPath = 'path/​to/​chromedriver'10driver = Chrome(driverPath)1112#Remote Client with Desired Capabilities13#Assuming the remote client is accessible via a URL14#Assuming that the remote client has the 'mobileEmulation' capability to set device orientation15options = Options()16options.add_experimental_option("mobileEmulation", {"deviceName": "Pixel 2 XL", "uorientation": "landscape"})17desired_capabilities = options.to_capabilities()18remote_driver = webdriver.Remote(19 command_executor='http:/​/​127.0.0.1:4444/​wd/​hub',20 desired_capabilities=desired_capabilities21) 2223#Test case implementation24url = "https:/​/​example.com"25driver.get(url)2627#Assuming the web application has the UID of elements to be tested28element1 = driver.find_element_by_id('uid1')29element2 = driver.find_element_by_id('uid2')3031#Check if both elements are visible on the page32if element1.is_displayed() and element2.is_displayed():33 print("Orientation-independent content and functionality passed")34else:35 print("Orientation-independent content and functionality failed")3637driver.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.

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