0% found this document useful (0 votes)
119 views

Page Object Model

The document discusses the Page Object Model (POM) design pattern for automation testing. POM advocates creating page class files for different pages in the application that need to be tested. Each page class contains web elements and methods specific to that page. This separates the page object code from test code, improves test maintenance, and makes tests more readable. The document outlines the key aspects of POM including creating page object layers for each page, test layers for test cases, a base class for common functionality, external config files, test data storage, utilities classes and test reports.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views

Page Object Model

The document discusses the Page Object Model (POM) design pattern for automation testing. POM advocates creating page class files for different pages in the application that need to be tested. Each page class contains web elements and methods specific to that page. This separates the page object code from test code, improves test maintenance, and makes tests more readable. The document outlines the key aspects of POM including creating page object layers for each page, test layers for test cases, a base class for common functionality, external config files, test data storage, utilities classes and test reports.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Page Object Model – POM

#Interviewer: Any idea about ‘Page Object Model’? Or POM?

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?

• Separation between Test scripts & Page Classes.

• Provides a single Object Repository along with associated functions.

• 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.

• Enhanced readability for Test 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

Steps for designing POM

Lets take an E-commerce application and we have LoginPage, HomePage, RegistrationPage,


SearchPage, AddToCartPage, PaymentPage

 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

 Second – We have to define Actions/Methods for features of that particular page.


 Actions and Methods like for eg in registration page we can define methods like clickOnSignInLink(),
fillRegForm(), checkLogo(), footerLinks() etc.
 So in 1st layer I will identify all the pages and create separate class files for every page and in that I
will define page objects and methods available in that page. This web object is defined in respective
pages for eg home page objects i will be defining in home page so we can say
WebElement/WebObjects are object Repositories – (OR – object Repository).
 OR means collection of all the WebElement/WebObjects.
 So we can say that Page layers are called Page libraries.
2nd Layer – Test Layer

 For each an every class we can create test layer.


 So in second layer I will create a separate class file for each an every page to write test cases for eg for
login page I will create class “LoginPageTest.java” file to write test cases of that page. So for all I will
create HomePageTest.java etc.
 This test layer will be written with the help of TestNG – all testing annotations

3rd Layer – Base Class

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.

4th Layer – Config.properties or Environment Variable

 In this I will define URL, username,password,browser and other properties.


 It is also called as environment variables.
 Interview question – how willyou define env variables? Ans – in config.properties
5th Layer – Store Data in Excel – TestData.xlsx

 In this file I will define my data and read the data using apache poi api.

6th Layer – Utilities

 Then we will create util class TestUtil.java class


 Utilities such as Screenshot() method will be there or some SendMail() or some common utility will be
there.
 I want to separate my common utilities and functions like Generic functions into TestUtil.java class.
7th – Test Report

 It can be HTML report, TestNG report or XML report or ExtendReport.


 This report needs to be generated to know how many test cases are pass or fail so on the basis of that
we will provide this particular report.

 So all this layers or components are created in separate packages.


 For page component it will be in com.qa.page, Test – com.qa.test, BaseClass – com.qa.base, Config –
com.qa.config, TestData – com.qa.testdata, TestUtil – com.qa.util, TestReports – Test-output/reports
folder.
 POM is also called as Page Chaining Model because every page is interconnected with each other.
 For eg on login page I login with user n pass and it will navigate to home page i.e my landing page so
home page is the landing page for login page.

 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

You might also like