Page Object Model

Page Object Model

Table of Contents

The Page Object model is a kind of design pattern which is popular in test automation for increasing the test maintenance and reducing the code duplication. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods. The benefit is when UI changes for that page the test doesn’t need to change, but the code within that page object needs to change.

The Design Pattern:

The design pattern is probably used in the selenium where web pages are represented by corresponding class and web elements which are represented by variables of the class; possibly interactions happen through the methods.

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

The advantages are of Page Object Model:

There is a clear separation between a test code and page specific code like locators and layout. The single repository for the services and operations offered by the page other than having these services scattered throughout the test. 

Reusability, we can reuse the page class for different tests if needed, that is we don’t have to write code again and again for identifying the code elements and also methods for interactions with them for every 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 element is added or the one which is existing is updated.

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

Implementation of Project Object Model:

We will see how to implement the page object model, as per the design we have separate classes for all the pages and where the objects are stored for each web page there should be a separate page class. 

Consider an example suppose we need to create page object for google search page. Firstly we have to create a page class for each web page like Google search page and create a class for search button and text box and store locators separately. 

  • Right click on the test file -> New-> package
  • Create class by right click on pages -> New-> class
  • Write the code to identify the web object separately to text box as well search button.
  • In the test case write the code where we are passing driver as a instance to open the class googlesearchpage.java
  • For google search button we have to write the test code.

Here we are referring the objects from one page class to another. There will be a lot of flexibility in how page objects should be designed. There are some rules for getting the desired maintainability of our test code.Page objects should not make any verifications and assertions. This is always a part of our test and it should be within the test code. The page object will contain the representation of the page and therefore the services the page provides via methods but no code associated with what’s being tested should be within the page object.

10 Responses

  1. The Page Object model is a kind of design pattern which is popular in test automation for increasing the test maintenance and reducing the code duplication. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods.
    The advantages are of Page Object Model:
    *Reusability
    *Maintainability
    *Readability

  2. Page Object Model, also known as POM, is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and improves test case maintenance. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods.
    The advantages are of Page Object Model
    1.Reusability- We can reuse the page class for different tests if needed, that is we don’t have to write code again and again for identifying the code elements and also methods for interactions with them for every test.
    2.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 element is added or the one which is existing is updated.
    3.Readability- As in the above picture, the page code is separated from the test code in turn which helps in code readability improvement.

  3. Page Object Mode is also known as POM ,is a design pattern which is very popular in Selenium Test Automation. It is useful in reducing code duplication and improves test cases maintenance. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods. The benefit is when UI changes for that page the test doesn’t need to change, but the code within that page object needs to change.
    The advantages are of Page Object Model:
    1.Reusability
    2. Maintainability
    3. Readability

  4. Page object model – Design pattern popular in test automation for increasing the test maintenance and reducing the code duplication. Interface to the page AUT. Consists of web elements and methods to interact with the web elements. When UI changes for the page, the test doesn’t need to change but the code within that page object needs to change.
    Advantages :
    Reusability – can reuse the page class for different tests
    Maintainability – can update code if any web element is added or the one which is existing is updated
    Readaptability – Code readaptability improvement

  5. Page object model:
    Page object model is popular in test automation. It is type of design pattern. It is used for increasing test maintenance and to reduce code duplication. I t consists of object oriented class. It also consists of web elements and methods to interact with the web interface.
    The design pattern is generally used in selenium where web pages are represented by corresponding classes and web elements are represented by variables of classes. The interaction happens through the methods.
    Adavantages of page object model are reusability, maintainability , readability

  6. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with them.

    The advantages are of Page Object Model
    1.Reusability- We can reuse the page class for different tests if needed, that is we don’t have to write code again and again for identifying the code elements and also methods for interactions with them for every test.
    2.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 element is added or the one which is existing is updated.
    3.Readability- As in the above picture, the page code is separated from the test code in turn which helps in code readability improvement.

    In order to automate the test cases,first we create objects of page classes and interact with them by calling methods. In order to to implement the page object model, as per the design we have separate classes for all the pages and where the objects are stored for each web page there should be a separate page class.

  7. The Page Object model is a kind of design pattern which is popular in test automation for increasing the test maintenance and reducing the code duplication. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods.
    The advantages are of Page Object Model:
    *Reusability
    *Maintainability
    *Readability

  8. The Page Object model is a kind of design pattern which is popular in test automation for increasing the test maintenance and reducing the code duplication. The page object is an object-oriented class which serves as an interface to a page of AUT. The Page class consists of web elements and methods to interact with web elements. When automating the test cases, we create objects of page classes and interact by calling methods. The benefit is when UI changes for that page the test doesn’t need to change, but the code within that page object needs to change.

    The Design Pattern:
    The design pattern is probably used in the selenium where web pages are represented by corresponding class and web elements which are represented by variables of the class; possibly interactions happen through the methods.
    The advantages are of Page Object Model:
    There is a clear separation between a test code and page specific code like locators and layout. The single repository for the services and operations offered by the page other than having these services scattered throughout the test.

    Reusability, we can reuse the page class for different tests if needed, that is we don’t have to write code again and again for identifying the code elements and also methods for interactions with them for every 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 element is added or the one which is existing is updated.

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

  9. The Page Object model is a design pattern that is popular in test automation for increasing test maintenance and reducing code duplication. The page object is an object-oriented class that serves as an interface to a page of AUT. When automating the test cases, we create objects of page classes and interact by calling methods. The benefit is when UI changes for that page the test doesn’t need to change, but the code within that page object needs to change.
    The advantages of the Page Object Model are Reusability, Maintainability, and Readability.

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