Page Object Model

As said earlier TAF got inspired from the implementation of Page Object Model in GEB and thought to provide the similar kind of features to the users of Java.

Page Classes

Pages in TAF have to extend PageClass provided by the framework. Once your page classes extend the said class different page object model utilities and features will become available to your page classes.

A common problem while using a Page Object model based automation framework is that the users have to manually handle the page navigation, class object initialization and page verification in the tests or in utils. TAF provides utility to do all at the same time and without much hassles. TAF allows the user to set a base url for the application under test. This is done by setting the property base_url in the taf configuration. TAF also allows user to provide explicit urls for your page classes. These urls can be extended urls to the defined base url or individual urls if required.

To represent your page class with a url just override method toUrl method of the parent PageClass as shown below.

	@Override
	public String toUrl() {
		return "";
	}

To provide an extended url to existing base url just provide the extended url. For ex. Your base url is www.google.com and you have a page class that represent the google mail home page which can be navigated using the url “www.google.com/mail”. Then you will have the toUrl method to return only the extended url i.e. “/mail”. Look at the following example written using the TAF Page Object Model.

public class GoogleMailPage extends PageClass {
	@Override
	public String toUrl() {
		return "/mail";
	}
}

In case you want to mention the whole url you can return the whole url too as mentioned below:

public class GoogleMailPage extends PageClass {
	@Override
	public String toUrl() {
		return "www.google.com/mail";
	}
}

TAF have util to (<page class>) method available in your test and page classes that will allow you to navigate between your page classes. The utility take the Page Class as class object and will automatically navigate your browser to the mentioned page class url returned by the toUrl method of the said page class. Once navigation is successful the utility will verify the that browser is on the respective page by executing the at method (covered later in this page) and return the said page class object. Taking the above mentioned “GoogleMailPage” class we can have following code, the said code will navigate the browser to the google mail page as represented the GoogleMailPage class.

GoogleMailPage googleMailPage = to(GoogleMailPage.class);

Page Verification - the “at” method

TAF provides utility to allow user to verify whether a feature/module or the page for which the Page class contains the functional methods is available on the browser or not. This utility allows user to validate before hand if the respective functionality or feature is available on the browser before using any of the functional methods represented in the Page Class. To define validation criteria for a particular Page class user just have to override a method named “at” on his page classes as shown in the example below.

public class GoogleMailPage extends PageClass {
	@Override
	public boolean at() {
		return browser.getDriver.getTitle().contains("Gmail");
	}
}

In the above example the “at” method returns true if the browser title contains text as Gmail. You can evaluate the condition using any other method as element being available or displayed etc.

To validate a Page you can simply use the at method in your page class or test-classes. In case the page validation fails the test will exit with an exception.

GoogleMailPage googleMailPage = at(GoogleMailPage.class);

There is another utility named isAt which returns true or false based on page verification.

	if(isAt(GoogleMailPage.class)){
		< do something>
	}

Note: Do not use explicit wait conditions of selenium webdriver in at method, this will delay page verification when there is a failure. In case you need to explicitly wait for a particular page class you can do so by using waitForPage method available as part of the util object defined in the PageClass and TestClass of the framework.

Page initialization - the “init” method

TAF allows user to call some code when initialising the Page classes. This can be done by overriding the init method of PageClass.

public class GoogleHomePage extends PageClass{
	
	GoogleLocator googleLocator;
	
	@Override
	public void init() {
		googleLocator = CustomPageFactoru.initElements(
							this.browser,GoogleLocator.class);
	}
}

In the above example the whenever user calls the to , at , isAt or getPageObject method in page or test classes the framework automatically create object of the said class and call the said init method.

Note: Any kind of locator initialization for page object model should be done inside the init method.

Test Classes

Test Classes in TAF have to extend TestClass provided by the framework. Once your test classes extend the said class different page object model utilities and features will become available to your test classes.