Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
Forked from andreidbr/soundPlayingTest.java
Created April 19, 2020 02:41
Show Gist options
  • Save evandrocoan/280ecaffa82eea9c4d5edc3382a2802c to your computer and use it in GitHub Desktop.
Save evandrocoan/280ecaffa82eea9c4d5edc3382a2802c to your computer and use it in GitHub Desktop.
A Selenium test to check if a sound is playing / has played
@Test(testName = "Listen for Sound", description = "Check that, when clicking the 'A' key, a sound is played", groups = {"01Drums"})
public void soundPlayTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
WebElement aKey = driver.findElement(By.xpath("/html/body/div/div[1]"));
Actions builder = new Actions(driver);
Action sendAKey = builder.moveToElement(aKey).sendKeys("A").build();
sendAKey.perform();
Thread.sleep(1000);
WebElement audio = driver.findElement(By.tagName("audio"));
Assert.assertNotEquals(audio.getAttribute("currentTime"), "0");
// Assert.assertTrue(Boolean.parseBoolean(audio.getAttribute("ended")));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment