Hint: "gebish" für Suchen
public class Selenium2Example {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
public class FindOwnersPage extends AbstractPage<FindOwnersPage> {
@FindBy(id = "findOwnersForm:search")
private WebElement search;
@FindBy(css = "input[type='text']")
private WebElement nameInput;
...
public FindOwnersResultPage searchForOwner(String name) {
nameInput.clear();
nameInput.sendKeys(name);
search.click();
return new FindOwnersResultPage().waitForIsLoaded();
}
}
@Test
public void testOpenNewOwnerPageFromOwnersList() {
final FindOwnersPage findOwnersPage = new FindOwnersPage();
findOwnersPage.get();
findOwnersPage.assertIsLoaded()
.searchForOwner("")
.assertIsLoaded()
.clickNewOwner()
.assertPageIsLoaded();
}
public abstract class AbstractPage<T extends AbstractPage<T>> extends LoadableComponent<T> {
private static WebDriver driver;
protected AbstractPage() {
driver = WebDriverHolder.getDriver();
PageFactory.initElements(driver, this);
}
@Override
protected final void load() {
getDriver().get(BASE_URL + pageUrl);
}
@Override
protected void isLoaded() throws Error {
assertTrue(getDriver().getCurrentUrl().endsWith(pageUrl));
}
public class WebDriverHolder {
private static WebDriver driver;
public static WebDriver getDriver() {
if (driver == null) {
...
driver = new FirefoxDriver(profile);
}
return driver;
}
public static void closeDriver() {
if (driver != null) {
driver.quit();
driver = null;
}
}
public static void resetDriver() {
if (driver != null) {
driver.navigate().to("");
if (driver.manage() != null) {
driver.manage().deleteAllCookies();
}
}
}
}
@RunWith(Arquillian.class)
public class TestDroneOnly {
@Drone
private WebDriver driver;
@ArquillianResource
private URL deploymentUrl;
@Test
public void testOpeningHomePage() {
driver.get(deploymentUrl + "/hello.jsf");
assertEquals("Java EE 7 Petclinic", driver.getTitle());
}
}
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_1.xsd">
<extension qualifier="webdriver">
<property name="browser">firefox</property>
<!--<property name="browser">phantomjs</property>-->
<!--<property name="browser">chrome</property>-->
</extension>
<extension qualifier="drone">
<property name="instantiationTimeoutInSeconds">120</property>
</extension>
</arquillian>
@Location("findOwners.jsf")
public class FindOwnersPage<T extends FindOwnersPage<T>> extends AbstractFindOwnersPage<T> {
@Page
private FindOwnersResultPage findOwnersResultPage;
public FindOwnersResultPage searchForOwner(String name) {
searchForOwnerInternal(name);
return findOwnersResultPage;
}
}
public abstract class AbstractFindOwnersPage<T extends AbstractFindOwnersPage<T>> {
@FindBy(css = "input[type='text']")
private WebElement nameInput;
@Page
private NewOwnerPage newOwnerPage;
...
public NewOwnerPage openNewOwnersPage() {
addNewOwnerLink.click();
return newOwnerPage;
}
protected void searchForOwnerInternal(String name) {
nameInput.clear();
nameInput.sendKeys(name);
search.click();
}
public abstract FindOwnersResultPage searchForOwner(final String s);
}
@Test
public void testOpenNewOwnerPageFromOwnersList() {
goTo(FindOwnersPage.class)
.assertIsLoaded()
.searchForOwner("")
.assertIsLoaded()
.openNewOwnersPage()
.assertIsLoaded();
}
class FindOwnersPage extends AbstractPetClinicPage {
static url ='findOwners.jsf'
static at = { pageHeader.present }
static content = {
pageHeader { $('h2', id: 'findOwners') }
nameInput { $('input', type:'text') }
searchButton { $('input', type: 'submit') }
addNewOwnerType { $('a', text: 'Add New Owner') }
}
FindOwnersResultPage searchForOwner(String name){
nameInput.value(name)
searchButton.click()
return waitForAtPage(FindOwnersResultPage)
}
NewOwnerPage openNewOwnersPage() {
addNewOwnerType.click()
return waitForAtPage(NewOwnerPage)
}
}
abstract class AbstractPetClinicPage extends Page {
static content = {
...
findOwnersLink { $("a", text: "Find Owners") }
}
...
FindOwnersPage toFindOwners() {
findOwnersLink.click()
return waitForAtPage(FindOwnersPage);
}
def <T extends Page> T waitForAtPage(Class<T> targetPageClass){
waitFor { browser.isAt(targetPageClass) }
return browser.page as T;
}
}
@RunWith(Arquillian)
class Test04Owner extends GebTest {
...
@Test
public void testOpenNewOwnerPageFromOwnersList() {
to(HelloPage)
.toFindOwners()
.searchForOwner('')
.openNewOwnersPage()
}}
baseUrl='http://localhost:8080/petclinic-all/'
driver = {
def FirefoxProfile profile = new FirefoxProfile();
...
def ffDriver = new FirefoxDriver(profile)
ffDriver.manage().window().maximize()
return ffDriver
}
waiting {
timeout = 10
retryInterval = 0.5
presets {
test {
timeout = 3
retryInterval = 0.5
}
}
}
environments {
'phantomjs' {
driver = {
final capabilities = new DesiredCapabilities()
capabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36")
final phantomJSDriver = new PhantomJSDriver(capabilities)
phantomJSDriver.manage().window().setSize(new Dimension(1028, 768))
return phantomJSDriver
}
}
chrome {
driver = {
final chromeDriver = new ChromeDriver()
chromeDriver.manage().window().maximize()
chromeDriver
}
}
}
public class OwnersTableFragment {
@Root
private WebElement root;
@FindBy(css = "tbody.rf-dt-b > tr")
private List<OwnersTableRowFragment> rows;
public List<OwnersTableRowFragment> findRowsByParameters(String firstName, String lastName, String address,
String city, String telephone) {
List<OwnersTableRowFragment> matchingRows = new ArrayList<>();
for (OwnersTableRowFragment row : rows) {
if (row.getLastName().equals(lastName) && row.getFirstName().equals(firstName)
&& row.getAddress().equals(address) && row.getCity().equals(city) && row.getTelephone().equals(telephone)) {
matchingRows.add(row);
}
}
return matchingRows;
}
}
Framework | Verfügbarkeit von Page Fragments |
Richfaces 4.5 | Final |
Primefaces | |
jQuery UI |
petBirthDateInput { module RichFacesCalendar, $('#editPetForm\\:petBirthDate') }
rowsInTable { moduleList OwnersTableRowModule, $('table.table tbody tr') }
class OwnersTableRowModule extends Module {
static content = {
cell(required: false ) { $("td", it) }
editOwnerLink(required: false ) { cell(0).find('a') }
name(required: false ) { cell(0).text() }
address(required: false ) { cell(1).text() }
city(required: false ) { cell(2).text() }
telephone(required: false ) { cell(3).text() }
}
ShowOwnerPage openDetails() {
editOwnerLink.click()
waitFor { browser.isAt(ShowOwnerPage) }
return browser.page as ShowOwnerPage
}
}
Einfach möglich
Existieren nicht (öffentlich)
@FindBy(id = "owners")
private WebElement owners;
...
ExpectedCondition<Boolean> expectedCondition
= ExpectedConditions.visibilityOfAllElements(Arrays.asList(owners));
Wait<WebDriver> wait = new WebDriverWait(driver, 3);
wait.until(expectedCondition);
guardHttp(buttonWhichMakesFullPageRefresh).click();
guardAjax(buttonWhichMakesAjaxRequest).click();
guardNoRequest(buttonWhichMakesNoRequest).click();
button.click();
waitGui()
.withMessage("Popup should be opened after clicking on that button!")
.until().element(popupPanel).is().visible();
waitFor {}
waitFor(message: 'Der neue Datensatz ist nicht erschienen'){}
waitFor(10) {}
waitFor(10, 0.5) {}
waitFor(message: 'Der neue Datensatz ist nicht erschienen', 'quick') {}
waitFor { theResultDiv.present }
class DynamicPage extends Page {
static content = {
dynamicallyAdded(wait: true) { $("p.dynamic") }
}
}
Browser.drive {
to DynamicPage
assert dynamicallyAdded.text() == "I'm here now"
}
public class WebDriverHolderCucumberLifeCycle {
@After(order = 1)
public static void resetDriver() {
WebDriverHolder.closeDriver();
}
}
class GebStepDefinitions {
String gebConfEnv = null
String gebConfScript = null
private Browser _browser
Configuration createConf() {
new ConfigurationLoader(gebConfEnv, System.properties, new GroovyClassLoader(getClass().classLoader)).getConf(gebConfScript)
}
Browser createBrowser() {
new Browser(createConf())
}
Browser getBrowser() {
if (_browser == null) {
_browser = createBrowser()
}
_browser
}
@After
void resetBrowser() {
if (_browser?.config?.autoClearCookies) {
_browser.clearCookiesQuietly()
}
_browser = null
}
def methodMissing(String name, args) {
getBrowser()."$name"(* args)
}
def propertyMissing(String name) {
getBrowser()."$name"
}
def propertyMissing(String name, value) {
getBrowser()."$name" = value
}
}
abstract class AbstractGebSamplerClient extends AbstractJavaSamplerClient implements Serializable {
@Override
Arguments getDefaultParameters() {
return new Arguments()
}
@Override
void setupTest(final JavaSamplerContext context) {
to(HelloPage)
}
@Override
void teardownTest(final JavaSamplerContext context) {
resetBrowser()
}
String gebConfEnv = null
String gebConfScript = null
private Browser _browser
Configuration createConf() {
new ConfigurationLoader(gebConfEnv, System.properties, new GroovyClassLoader(getClass().classLoader)).getConf(gebConfScript)
}
Browser createBrowser() {
new Browser(createConf())
}
Browser getBrowser() {
if (_browser == null) {
_browser = createBrowser()
}
_browser
}
void resetBrowser() {
if (_browser?.config?.autoClearCookies) {
_browser.clearCookiesQuietly()
}
}
def methodMissing(String name, args) {
getBrowser()."$name"(*args)
}
def propertyMissing(String name) {
getBrowser()."$name"
}
def propertyMissing(String name, value) {
getBrowser()."$name" = value
}
}
Selenium Page Objects | Arquillian Graphene | geb | |
Arquillian Deployment | |||
Arquillian Suite Deployment | |||
Arquillian Warp | |||
Cucumber | |||
Cucumber mit Arquillian Deployment | |||
Cucumber mit Arquillian Suite Deployment | |||
jMeter |
Selenium Page Objects | Arquillian Graphene | geb | |
Vereinfachte Screenshoots | - | ||
Javascript einfacher im Browser ausführen | - | ||
Download | |||
Konfiguration von Browser | |||
Konfiguration von Timings | |||
Angepasste Selektoren | |||
jQuery Selektoren | |||
AngularJS |