Do not have audio that plays automatically on the page. When providing audio,also provide an easy way to disable the audio and adjust the volume.
Language: Java
Framework: Selenium 4
1//Assuming the web page has an audio player2//Assuming the audio player has an id attribute as 'audio-player'34import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;89public class AudioPlayerTest {1011 public static void main(String[] args) {12 //Set the path to the chrome driver13 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");14 15 //Create instance of chrome driver 16 WebDriver driver = new ChromeDriver();17 18 //Navigate to the web page 19 driver.get("http://www.example.com");20 21 //Disable automatic audio play and check volume control22 WebElement audioPlayer = driver.findElement(By.id("audio-player"));23 String currentSrc = audioPlayer.getAttribute("src");24 String volume = audioPlayer.getAttribute("volume");25 26 //Ensure that audio is not played automatically27 assert currentSrc == null : "Automatic audio play is not disabled";28 29 //Ensure that audio volume can be adjusted30 assert volume.isPresent() : "No volume control found";31 32 //Print test results33 System.out.println("Audio player test passed successfully");34 35 //Close the browser36 driver.quit();37 38 /*39 //Uncomment below code to connect to remote client with desired capabilities40 DesiredCapabilities capabilities = DesiredCapabilities.chrome();41 capabilities.setBrowserName("chrome");42 43 //hub address44 String hubUrl = "http://localhost:4444/wd/hub";45 46 //Create instance of chrome driver 47 WebDriver driver = new RemoteWebDriver(new URL(hubUrl), capabilities);48 */49 }5051}
Language: Python
Framework: Selenium 4
1from selenium import webdriver23# Assume the website URL and driver path4url = "https://www.example.com"5driver_path = "/path/to/chromedriver"67# Start local driver (Chrome)8driver = webdriver.Chrome(executable_path=driver_path)910# Set desired capabilities for remote client (Firefox)11# desired_capabilities = {'browserName': 'firefox'}12# remote_driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=desired_capabilities)1314# Navigate to the website15driver.get(url)1617# Assume there is an audio element on the page with an ID of 'audio'18audio_element = driver.find_element_by_id('audio')1920# Check that the audio does not play automatically21assert not audio_element.get_attribute('autoplay'), "Error: Audio plays automatically"2223# Assume there is a button with an ID of 'audio-toggle' that toggles the audio on and off24audio_toggle_button = driver.find_element_by_id('audio-toggle')2526# Click the audio toggle button to disable the audio27audio_toggle_button.click()2829# Assume there is a slider element with an ID of 'audio-volume' that adjusts the volume30audio_volume_slider = driver.find_element_by_id('audio-volume')3132# Assume the volume is initially set to 50%33assert audio_volume_slider.get_attribute('value') == '50', "Error: Volume is not initially set to 50%"3435# Assume the user wants to adjust the volume to 75%36audio_volume_slider.set_attribute('value', '75')37assert audio_volume_slider.get_attribute('value') == '75', "Error: Volume is not set to 75%"3839# Close the driver40driver.quit()4142# Uncomment to use remote client with desired capabilities43# remote_driver.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.
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