PAGE OBJECT MODEL, PAGE OBJECT DESIGN PATTERN WITH and WITHOUT PAGE-FACTORY
_______________________________________________________________________________
1. Each page within the AUT (Application Under Test) is considered as a Java class./ A major functionality within page could be considered as class or several functionality within a page could be considered as inner class.
2. Identify what you need to test on a particular page.
3. Identify all the locators on that page which are required to perform identified tests
I am taking an example of Wordpress as AUT
Here I will show you example of Page Object Design Pattern using PageFactory as well as without using PageFactory.
// login page locators
By userName = By.id("user_login");
By password = By.id("user_pass");
By loginButton = By.id("wp-submit");
The main difference between PageFactory and non PageFactory design pattern is, in PageFactory design pattern the locators are used within @FindBy annotation with How enum and that returns an object of type WebElement where as in non PageFactory design pattern the locators are used as an argument to "By class" static methods.
which returns an Object of type By.
Non pagefactory
By userName = By.id("user_login");
By password = By.id("user_pass");
By loginButton = By.id("wp-submit");
PageFactory using @FindBy annotation
@CacheLookup
@FindBy(how = How.ID, using = "user_login")
WebElement userName;
@CacheLookup
@FindBy(how = How.ID, using = "user_pass")
WebElement password;
@CacheLookup
@FindBy(how = How.ID, using
WebElement loginButton;
In non-page factory design we need an argument constructor which which will pass driver instance from test class to page class.
In pageFactory design approach we use PageFactory.initElements, this initElements takes argument as
driver The driver that will be used to look up the elements and
pageClassToProxy A class which will be initialised.
which return An instantiated instance of the class with WebElement and List<WebElement> fields proxied
Selenium is the best tool ever to test an application effectively. Your blog made me to realize that through the best examples you have explained. Thanks for sharing a wonderful article.
ReplyDeleteRegards:
Selenium Training Chennai
software testing selenium training