PAGE OBJECT MODEL DESIGN PATTERN

PAGE OBJECT MODEL DESIGN PATTERN

Table of Contents

This page object model is a kind of design pattern. It is popular for test automation. It increases the test maintenance and reducing code duplication. The page object is an object-oriented class. It serves as an interface to a page of software under test. Page class consists web elements and methods to interact with other web elements. For automation of the test cases, object of page classes are created and interact by calling methods. Even if these user interface pages change the test need not be changed. Only the code in the page object can be changed. 

The Design Pattern:

The design pattern used in the selenium as per web pages are shown by corresponding class and web elements shown by variables of the class possibly interactions happens through the methods.

https://media.geeksforgeeks.org/wp-content/uploads/20190703221724/POM2.png

The advantages are:

It is a clean division between a test code and page specific code like locators and layout. This individual repository for the services and operations provides by the page other than having these services scattered allover the test.

Reusability, can be reused by the page class for different tests if needed that is we don’t have to code again and again for identifying the code elements and methods for interactions for each test.

Maintainability, the above picture shows that the test case and page class are different from each other which means we can update code if any web elements is added or the one which is existing is updated.

Readability, as above picture the page code is separated from the test code in turn which helps in code readability improvement.

Implementation

We see the way to implement the page object model, as per the design. There are separate classes for all the pages. The objects for each web page are in its own page class. Consider an example suppose we need to create page object for Facebook search page. Firstly, Facebook page should have its own page. A class for search button and text box and store locators are created separately.

Right click on the test file -> New-> package

PAGE OBJECT MODEL DESIGN PATTERN
PAGE OBJECT MODEL DESIGN PATTERN

we should form class by right click on pages ->New->class

PAGE OBJECT MODEL DESIGN PATTERN

Write the code to identify the webobject separately to textbox as well search button

PAGE OBJECT MODEL DESIGN PATTERN

In the test case write the following code where we are passing driver as a instance to open the class googlesearchpage.java

PAGE OBJECT MODEL DESIGN PATTERN

For googlesearch button we have to write the test code as

PAGE OBJECT MODEL DESIGN PATTERN

Here the objects of page class is referred to other. There will be lot of flexibility in how page objects should be designed. There are some rules for getting desired maintainability of our test code.

Any verifications and assertions are not made in page objects. It is always within the test code. The page object has the representation of the page. Hence the services the page provides via methods but no code associated with what’s being tested should be within the page object.

The important idea behind this page object model is creating a separate class or module for each component of the application that is being tested. Each class that will represent a particular page and binds it in related UI elements and also their corresponding actions.

The main components and concepts in this model are:

1. Page objects- Each page  or may be component of the application that has a corresponding page object class.This class that contains the definitions of the UI elements on the page are those elements that are performed.

2. Encapsulation- Page object classes may bind the entire detail information of the UI elements  and also their interactions,by providing a separation between the test automation code and UI implementation.

Questions

1. What is Page object model?

2. What are the components of page object model?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training
Enroll Free demo class