13

I am writing tests for an HTML5 game, and I want to check that the audio is loading and starting correctly.

Is there a way to check this using Selenium? or do I need to do this at the OS level?

MasterScrat
  • 7,090
  • 14
  • 48
  • 80

2 Answers2

3

You could check the audio element, after it should've started playing:

WebElement audio = driver.findElement(By.tagName("audio"));
String currentTime = audio.getAttribute("currentTime");
try {
    assertTrue(Double.parseDouble(currentTime) > 0.0);
} catch(NumberFormatException ex) {
    assertEquals(ex, null);
}

If it failed to load, or never started, then this test should fail.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
0

I always respond to questions like this with "Tell me how a human being would check that ...". The answer is this case would be to listen to the audio and see if what's supposed to be playing is. You're not going to be able to make a computer do that easily.

Ross Patterson
  • 9,527
  • 33
  • 48
  • Selenium doesn't do OS-level anything. – Ross Patterson Jun 27 '13 at 23:12
  • 4
    Related: http://stackoverflow.com/questions/26042241/detecting-if-sound-is-playing-in-selenium I would like to know if a tab is playing audio, the same way that Chrome puts the little speaker icon in the tab. Is there a way with selenium to detect if that speaker icon is there perhaps? – Joe Sep 25 '14 at 16:45