Getting started

Download PopperFramework

Add the given jars to your WebDriver project

Or just use Maven:

For projects describing PageObjects:
<dependency>
	<groupId>org.popperfw</groupId>
	<artifactId>Interfaces</artifactId>
	<version>0.4</version>
</dependency>
	
For projects running tests:
<dependency>
	<groupId>org.popperfw</groupId>
	<artifactId>Core</artifactId>
	<version>0.4</version>
</dependency>
<dependency>
	<groupId>org.seleniumhq.selenium</groupId>
	<artifactId>selenium-java</artifactId>
	<version>${webdriver.version}</version>
</dependency>
	

Creating a simple page object

Defining a PageObject is done by defining an annotated interface.

@Page
public interface LoginSite {
  @Locator(xpath="//input[@name='username']")
  ITextBox usernameTextbox();

  @Locator(xpath="//input[@name='password']")
  ITextBox passwordTextbox();

  @Locator(cssSelector=".submitLoginButton")
  IButton submitLoginButton();

  @Locator(id="register")
  ILink registerLink();
}

Instantiating PageObjects

public class LoginTest {
    protected IPoFactory factory;

    @Before
    public void setup() {
        WebdriverContext context = new WebdriverContext();
        context.getDefaultConfig().setBrowser(Browser.FIREFOX);
        context.getDefaultConfig().setBaseUrl("http://some.location.com/");
        factory = context.getFactory();
    }

    @Test
    public void testLogin() {
        LoginSite login = factory.createPage(LoginSite.class);
        login.open();
        login.usernameTextbox().type("Michael");
        login.passwordTextbox().type("secret");
        login.submitLoginButton().click();
    }
}

Using parameters

@Page
public interface Indexsite {
  @Locator(xpath = "//a[text()='{0}']")
  ILink linkByName(String linkname);
}

Frames (since 0.3)

The content of a frame is handled as a normal PageObject. You have just to annotate the your Element with the @Frame-Annotation
@Page
public interface PageWithIframePO {
	@Frame(id="iframe")
	PoDescribingFrame myIframe();
}
You may even access elements inside a frame from an PageObject describing content outside that frame.
@Page(name="Page with Frames")
public interface PageWithIframePO {
	@Frame(id="iframe")
	@Locator(id="idLocator")
	ILabel directFrameAccess();
}

Opening sites

An open-method can be declared, too. This can be used, to open the site by entering the url

@Page
public interface OpenedSitePO {
    @PageAccessor(uri="/pages/open.html")
    void open(); 
    // => http://some.location.com/pages/open.html

    @PageAccessor(uri="/pages/open.html?name={0}&password={1}")
    void open(String name, String password);
    // => http://some.location.com/pages/open.html?name=para1&password=para2

    @PageAccessor(uri="/pages/open.html")
    void openMapSimple(Map<String, String> parameters);
    // => http://some.location.com/pages/open.html?key1=value1&key2=value2

    @PageAccessor(uri="/pages/open.html?para1=val1")
    void openMapWithExistingParameters(Map<String, String> parameters);
    // => http://some.location.com/pages/open.html?para1=val1¶sFromMap

    @PageAccessor(absoluteUri="http://google.de?q={1}")
    void search(String query);
    // => http://google.de?q=para1
}

Getting access to page attributes

There are some Annotaions giving you access to site information

@Page
public interface SimplePO {
    @PageSource
    String getHtml();

    @Title
    String getTitle();
}

Configure Popper

You need to tell Popper how tests should be executed, f.e. where to find the SUT, what browser to use, ...

Configure by Sourcecode

WebdriverContext context = new WebdriverContext();
context.getDefaultConfig().setBaseUrl("http://your.system.under.test.com");
context.getDefaultConfig().setBrowser(Browser.FIREFOX);
context.getDefaultConfig().setImplicitTimeout(3000);
context.getDefaultConfig().setLocale(Locale.ENGLISH);
context.getDefaultConfig().setSeleniumHost("http://your.remoteserver.com:4444");
IPoFactory factory = context.getFactory();

Configure Popper by Propertyfile

WebdriverContext context = new WebdriverContext();
context.getDefaultConfig().configureByPropertyfile("/path/to/resource/in/classpath");
IPoFactory factory = context.getFactory();

The Propertyfile looks like this

browserName=FIREFOX
seleniumHost=http://your.remoteserver.com:4444
implicitTimeout=3000
browserLanguage=en_US
baseUrl=http://your.system.under.test.com