Page Object Model
Page Object Model
One of the most popular Design pattern now-a-days. As the name suggests,
• Page: Any web page you want to interact with. E.g. Registration page, Login page, Homepage, Search
page, Checkout page, etc.
• Object: Object-oriented programming jargon. Create a class containing properties (variables) &
behavior (functions). Objects are instances of a class.
Combining these – ‘Page Object’ is nothing but creating ‘Objects’ (classes) of different Web pages which
the script needs to interact with. Create a page object containing all the page elements and associated
methods which are specific to a page. The benefit?
• You need not identify the web elements in each & every script.
• If locator value changes for an element (UI changes) – change it in the respective page object, which is
then used in different scripts. One change = reflected in all scripts.
Create Page Object for all Web pages >> Based on Test, navigate to the required page & access Page
specific methods. When navigating to other page, return that particular page object. Else return the
current page object.
Note: We can have multiple Page Objects even for a single web page – say, Header, Footer, Main page,
etc.
POM is no a framework it is a design pattern or an approach
Using Data driven framework we can approach this POM design
Writing test case using TestNG
The concept of POM is that for every page we have to create separate java class.
We will design it by layer wise.
1st layer - Page layer
st
1 layer is page layer and under this layer following points defined.
First - We have to define objects – WebOjects/WebElements for every page.
Objects and Element are like for login page – username, password, login button, forgot password,
submit button, registration link this are called Elements
So before doing above two layer I will define Base class TestBase.java and it is most important class.
This is the parent class for the all class define in 1st and 2nd layer
In this Base Test Class all the pre requisites are defined for eg initializing Webdriver driver = new
ChromeDriver().
Initialization of properties or launching browser or timeout or maximize window all the required
methods .
maximizeWindow(), pageloadTimeOut(), implicitWait(), deleteAllCookies(), getUrl() etc.
We will use the concept of inheritance, parent and child relationship and then access all this methods
from parent class directly, it is only one time activity that we are defining all this method in base class.
So all this methods inheriting the properties of the base class.
In this file I will define my data and read the data using apache poi api.
So at the time of interview they wll ask what is POM and how the architecture of your framework?
So explain all this 7 components and also technology wise we will have.
Java – to write the code.
Selenium Webdriver
TestNG – to write test cases.
Maven – for creating build
Apache POI – to read the data from excel file
ExtendReport/TestNGReport – to generate reports.
Log4j API – to generate the logs
Jenkins – for CI to trigger the build
Git Repo – to push the code for checkin and checkout point of view.
Selenium GRID – for parallel testing.
Browsers – Firefox/Chrome/Safari.
Platforms – MAC/Windows/Linux
Or on different VMs like SauceLabs/BrowserStack this are the diff cloud platforms to execute the test
cases