Skip to content

Instantly share code, notes, and snippets.

@andreidbr
Created March 18, 2018 16:31
Show Gist options
  • Save andreidbr/f5e6e20d3d651c4336933b02febefeef to your computer and use it in GitHub Desktop.
Save andreidbr/f5e6e20d3d651c4336933b02febefeef to your computer and use it in GitHub Desktop.
A simple for loop with Selenium
@Test(testName = "Check all sounds", description = "Check that, when clicking every key, a sound is played", groups = {"01Drums"})
public void soundsPlayTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
List<WebElement> keyList = driver.findElements(By.className("key"));
List<WebElement> audioList = driver.findElements(By.tagName("audio"));
Actions builder = new Actions(driver);
for (int i = 0; i < keyList.size(); i++) {
Action sendKey = builder.moveToElement(keyList.get(i)).sendKeys(String.valueOf(keyList.get(i).getText().charAt(0))).build();
sendKey.perform();
Thread.sleep(1000);
Assert.assertNotEquals(audioList.get(i).getAttribute("currentTime"), "0");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment