Wiki

Clone wiki

aport / Example - Simple Page

Example of a simple page containing one directly included WebElement and one widget.

Notable details:

  • page is provided with WebDriverHandle fro initilization -- this is class with WebDriver instance and associated objects as waits, JavaScript executor etc.

  • Page.setPageUrlParams() is used to set page URL relative to the site URL provided by MySiteConfig behind the scene.

  • resolve() called with two groups, "default" and "solitary-elements" -- it will resolve all resolvable fields without a group specified ("default" is the name of the default group) and those belonging to the group named "solitary-elements"

  • Page.getWait() is shortcut to the default wait in WebDriverHandle

  • when Page.checkOpened() fails, it should throw InvalidPageException

#!java

package com.example.xyz;

import com.example.xyz.MySiteConfig;
import org.bithill.selenium.Page;
import org.bithill.selenium.ResolveBy;
import org.bithill.selenium.Site;
import org.bithill.selenium.WebDriverHandle;
import org.openqa.selenium.WebElement;

/** Page for ... */
@Site(config = MySiteConfig.class)
public class MyPage extends Page {

    private MyWidget myWidget;

    @ResolveBy(value = "id=element-id", groups = "solitary-elements")
    private WebElement solitaryElement;

    public MyPage(WebDriverHandle driverHandle) {
        super(driverHandle);
        setPageUrlParams("url/relative/to/site/url");
    }

    @Override
    // called as a last step of Page.open()
    public MyPage checkOpened() {
        try {
            getWait().until(PREDICATE_TO_CHECK_THE_REQUESTED_PAGE_IS_OPENED);
        }
        catch (org.openqa.selenium.TimeoutException ex) {
            throw new InvalidPageException(getClass().getSimpleName() + " not loaded", ex);
        }
        return this;
    }

    public void pageMethod(String arg1, String arg2) {
        open();
        resolve("default","solitary-elements");
        myWidget.init();
        myWidget.doSomething(args);
    }
}

Updated