Skip to content

Instantly share code, notes, and snippets.

@prule
Created August 17, 2013 08:29
Show Gist options
  • Select an option

  • Save prule/6255912 to your computer and use it in GitHub Desktop.

Select an option

Save prule/6255912 to your computer and use it in GitHub Desktop.
My version of an Abstract Page Object for using with Selenium and JBehave - utility behaviour for clicking links by text, selecting a JSF/PrimeFaces selectOne option, and waiting for ajax to complete.
import net.thucydides.core.pages.PageObject;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public abstract class AbstractPage extends PageObject {
public AbstractPage(WebDriver driver) {
super(driver);
}
public void waitForAjax() {
waitForRenderedElements(By.className("ajaxLoadingImg"));
waitForRenderedElementsToDisappear(By.className("ajaxLoadingImg"));
}
public void clickLinkWithText(String linkText) {
getDriver().findElement(By.linkText(linkText)).click();
}
public void selectOne(String idPrefix, String value) {
if (StringUtils.isNotBlank(value)) {
getDriver().findElement(By.id(idPrefix + "_label")).click();
getDriver().findElement(By.xpath("//div[@id='" + idPrefix + "_panel']/div/ul/li[text()='" + value + "']")).click();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment