For pre-recorded video (without audio), provide a text alternative or audio descriptions that provide the same information presented.
Language: Java
Framework: Selenium 4
1//Assumptions:2//1. The video element has a specific ID in the HTML code3//2. The text alternative is displayed through the 'alt' attribute of the video element4//3. The audio description is provided through a separate audio element with a specific ID5//4. The audio element is hidden from sight to prevent visual distraction67//Code to implement test case in Selenium 4 with Java:89//Import required libraries for Selenium WebDriver10import org.openqa.selenium.By;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.chrome.ChromeDriver;1415public class AccessibilityTesting {1617 public static void main(String[] args) {1819 //Set the path of the ChromeDriver executable20 System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");2122 //Create a new instance of ChromeDriver23 WebDriver driver = new ChromeDriver();2425 //Navigate to the webpage with the video element26 driver.get("https://www.example.com/video-page");2728 //Find the video element by its ID29 WebElement video = driver.findElement(By.id("video-element-id"));3031 //Check if the video has a text alternative32 String textAlternative = video.getAttribute("alt");33 if(textAlternative.equals("")) {34 System.out.println("Text alternative is missing for pre-recorded video");35 }3637 //Find the audio element by its ID38 WebElement audio = driver.findElement(By.id("audio-element-id"));3940 //Check if the audio description is provided41 boolean isAudioHidden = audio.getCssValue("display").equals("none");42 if(isAudioHidden) {43 System.out.println("Audio description is missing for pre-recorded video");44 }4546 //Close the browser47 driver.quit();48 }49 50 //Code to connect to remote client with desired capabilities:51 //Assuming the remote client is using a Linux server with Firefox 90.0 and supports Javascript52 WebDriver driver;53 String REMOTE_URL = "http://<remote-url>:4444/wd/hub";54 String PLATFORM = "Linux";55 String BROWSER_NAME = "firefox";56 String BROWSER_VERSION = "90.0";5758 //Set desired capabilities59 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();60 desiredCapabilities.setCapability(CapabilityType.PLATFORM_NAME, PLATFORM);61 desiredCapabilities.setCapability(CapabilityType.BROWSER_NAME, BROWSER_NAME);62 desiredCapabilities.setCapability(CapabilityType.BROWSER_VERSION, BROWSER_VERSION);63 desiredCapabilities.setCapability("javascriptEnabled", true);6465 //Connect to remote client66 try {67 driver = new RemoteWebDriver(new URL(REMOTE_URL), desiredCapabilities);68 } catch (MalformedURLException e) {69 e.printStackTrace();70 }7172}
Language: Python
Framework: Selenium 4
1#Assumption: This test case will be executed on a web application23from selenium import webdriver4from selenium.webdriver.common.desired_capabilities import DesiredCapabilities56#Connecting to Remote Client with Desired Capabilities7#Assumption: Remote client has desired capabilities already set up8capabilities = DesiredCapabilities.CHROME9driver = webdriver.Remote(command_executor='http://remote-client-ip:port/wd/hub', desired_capabilities=capabilities)1011#Initiating new instance of ChromeDriver12#Assumption: ChromeDriver is installed and executable path is set in the system environment variables13driver = webdriver.Chrome()1415#Navigate to web application URL16driver.get("https://www.example.com")1718#Locate the pre-recorded video element19video_element = driver.find_element_by_xpath("//video[@class='pre-recorded-video']")2021#Check if video has audio description or text alternative22if video_element.get_attribute("aria-describedBy") is not None:23 print("Video has audio description")24else:25 print("Video does not have audio description or text alternative") 2627#Close the browser window28driver.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