Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created December 13, 2012 11:03
Show Gist options
  • Save freynaud/4275759 to your computer and use it in GitHub Desktop.
Save freynaud/4275759 to your computer and use it in GitHub Desktop.
public class ABBLayoutTest {
@Test
public void home() throws InterruptedException {
driver.get("http://new.abb.com/about");
Slider slider = new Slider(4);
for (int i = 0; i < 4; i++) {
slider.slide();
// TODO : check against the CMS that the title is correct.
System.out.println(slider.getTitle());
}
}
class Slider {
private int expectedSize;
private int index = 0;
private List<WebElement> elements;
private String title = "";
public Slider(int expectedSize) {
this.expectedSize = expectedSize;
init();
}
private void init() {
elements = driver.findElements(By.cssSelector(".nivo-controlNav > a"));
if (elements.size() != expectedSize) {
takeScreenshot("BUG ? expected " + expectedSize + "elements.");
}
Assert.assertEquals(elements.size(), expectedSize);
}
public void slide() {
index++;
if (index == expectedSize){
index=0;
}
elements.get(index).click();
title = waitForTitleTochange(title);
takeScreenshot(title);
}
public String getTitle() {
return title;
}
private String waitForTitleTochange(String currentTitle) {
String newOne = currentTitle;
while (currentTitle.equals(newOne)) {
try {
newOne = driver.findElement(By.cssSelector(".slider .textContainer > h2")).getText();
} catch (StaleElementReferenceException e) {
// ignore.
}
}
return newOne;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment