Avoid activating functionality through motion (e.g., shaking a phone). If motion triggers functionality, provide a way to disable the motion trigger and provide an alternative way to activate the functionality.
Language: Java
Framework: Selenium 4
1//Assuming the web app is designed for mobile devices only2//Assuming the website has a button that is meant to be clicked to activate a particular functionality3//Assuming there is an input box that can be used to disable motion triggers45//Import Selenium libraries6import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.remote.DesiredCapabilities;11import org.openqa.selenium.remote.RemoteWebDriver;1213import java.net.URL;1415public class AccessibilityTesting {1617public static void main(String[] args) throws Exception {1819//Using local driver20System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");21WebDriver driver = new ChromeDriver();2223//Using remote client with desired capabilities24DesiredCapabilities desiredCapabilities = new DesiredCapabilities();25desiredCapabilities.setBrowserName("chrome");26URL remoteUrl = new URL("http://localhost:4444/wd/hub");27RemoteWebDriver driver1 = new RemoteWebDriver(remoteUrl, desiredCapabilities);2829//Navigating to the website30driver.navigate().to("https://www.example.com");3132//Locating the button that activates the functionality33WebElement activateButton = driver.findElement(By.id("buttonId"));3435//Disabling motion triggers by entering "disable" in the input box36WebElement inputBox = driver.findElement(By.id("inputBoxId"));37inputBox.sendKeys("disable");3839//Clicking the activate button to test if motion triggers the functionality40activateButton.click();4142//Verifying that the functionality is not activated43boolean functionalityActivated = driver.findElement(By.id("functionalityId")).isEnabled();44if (functionalityActivated) {45//If the functionality is activated, providing an alternative way to activate it46WebElement alternativeButton = driver.findElement(By.id("alternativeButtonId"));47alternativeButton.click();48}4950}51}
Language: Python
Framework: Selenium 4
1# Assumptions: 2# - The web application has motion-activated functionality that needs to be tested for accessibility.3# - The application has a toggle button or setting to disable motion triggers.4# - There is an alternative way to activate the same functionality through a non-movement input.56# Import required Selenium libraries7from selenium import webdriver8from selenium.webdriver.common.keys import Keys9from selenium.webdriver.common.action_chains import ActionChains1011# Create a new instance of the Firefox driver12driver = webdriver.Firefox()1314# Navigate to the web application page with motion-activated functionality15driver.get("https://example.com/path/to/motion/functionality")1617# Check if motion triggers functionality18if driver.execute_script("return 'onDeviceMotion' in window"):19 # Disable motion triggers if they exist20 driver.execute_script("window.addEventListener('devicemotion', function(event) {"21 "event.preventDefault();"22 "event.stopPropagation();"23 "}, true);")2425# Find the non-movement input element that activates the same functionality26non_movement_input = driver.find_element_by_css_selector("#non-movement-input")2728# Use the non-movement input to activate the same functionality29ActionChains(driver).click(on_element=non_movement_input).perform()3031# Optional: connect to remote client with desired capabilities32# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities33# capabilities = DesiredCapabilities.FIREFOX.copy()34# capabilities['platform'] = "WINDOWS"35# capabilities['version'] = "10"36# driver = webdriver.Remote(37# command_executor='http://127.0.0.1:4444/wd/hub',38# desired_capabilities=capabilities39# )4041# Close the browser42driver.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.
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