You are viewing our old blog site. For latest posts, please visit us at the new space. Follow our publication there to stay updated with tech articles, tutorials, events & more.

Page Object Pattern

0.00 avg. rating (0% score) - 0 votes

Before discussing about “Page Object Pattern”, let’s understand what is Test Specification and Test Implementation?

There is a difference between Test Specification and Test Implementation

Test Specification – What to Test?

Test Implementation – How to Test?

For Example, Test Specification is “When user enters username and password and clicks the login button, then he is logged in and can see his Dashboard”. This describes a scenario – it’s a specification of what the test should do.

However, Test Implementation has to deal with following things:

  • The username field is found with the web element “username_txt”
  • The password field is found with the web element “pwd_txt”
  • The login button is found with the web element “#loginButton input”

In future, if the layout of the Login page will change, then

Does the Test Specification change? – No

  • The User still needs to provide credentials and click the login button.

Does the Test Implementation change? – Yes

  • As the layout has been changed.

Separating Test Specification from Test Implementation makes Tests more robust. If I change how login works, I don’t have to change every single test that needs a logged in user.

In Selenium, we can separate Test Specification from Test Implementation by using Page Object Pattern.

Page Object Pattern

The Page Object Pattern is used for abstracting the application’s pages in order to reduce the coupling between test cases and AUT (Application Under Test).

The Page Object pattern represents the screens of your web app as a series of objects and encapsulates the features represented by a page. A Page Object holds the details of all the elements on a web page that might be involved in an automated test.

Page Object Pattern is a design pattern that can be implemented as a selenium best practices.

How does it work?

Page Object Pattern is a pattern that displays user interface as a class. In addition to user interface, Functionalities/Features of the page are also described in this class. This provides a bridge between page and test as shown below:


Page object framework is partially component based as we try to divide it into different pages and those pages hold the logic or actions within it. But the Test layer is completely request based as the tests execute a sequence of actions based on the request made.

Some points that Page Object Pattern suggests are:

  1. Model your application UI pages as classes in your framework.
  2. Method names inside the page class should represent the actual functionality that it performs.

We follow Page Object Pattern at Naukri?

To map the web page’s components inside the test automation code we use the Page Object Pattern.

This pattern help us to reuse the code to access web-page’s components as shown in the following Diagram:


The POM structure also help us with debugging. The more exception handling and logging we add to our page class, the easier it is to pinpoint where exactly a test went wrong. It highlights the following advantages that come with using page objects:

  1. Readability

Tests are easy to read, even to a tester who is new to the project.

  1. Maintainability

Separating test cases and user action from each other is essential to have a maintainable test suite. Modifying at one place allows the test to adapt to a changing environment.

  1. Clarity:

Anybody who is new in the Team can easily navigate through the code base and can understand what already exists and what needs to be added, this will nullify writing duplicate code and improves reusability (indirectly) for the Component/Feature.

Points to Remember

  • The public methods should represent the services that the page offers
  • Generally don’t make assertions in Page Objects
  • Need not to represent an entire page


3 thoughts on “Page Object Pattern

  1. Aw, this was a very good post. Taking a few minutes and actual
    effort to create a very good article… but what can I say… I procrastinate a lot and don’t manage to
    get nearly anything done.

  2. Fine way of describing, and pleasant post to get information regarding my presentation subject matter,
    which i am going to present in university.

Comments are closed.