Check if audio is playing correctly using Selenium

前端 未结 2 1726
無奈伤痛
無奈伤痛 2020-12-30 11:53

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

2条回答
  •  温柔的废话
    2020-12-30 12:16

    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.

提交回复
热议问题