Page Object Model

Page Object Model

Table of Contents

Modern software applications evolve fast, and so should the way we test them. As systems grow in complexity with frequent releases, feature additions, and UI changes, test automation becomes essential. But automation is only effective when it is structured, reusable, and easily maintainable. This is where the Page Object Model (POM) shines.

POM is one of the most widely adopted design patterns in automation testing. Whether you’re learning through Quality analyst courses understanding POM is a core skill that sets strong testers apart.

In this blog, we’ll explore what POM is, why it matters, how to implement it, and how it transforms testing efficiency across projects.

Page Object Model

Introduction: Why Automation Needs Better Design

Imagine you are testing a web application like an e commerce website. You automate login, product search, checkout, and profile update features. Everything runs smoothly until the UI changes.

A single button name change, a new locator, or a modified layout may break dozens of test scripts. You now spend hours fixing broken code scattered throughout your framework.

This is the biggest challenge of poorly structured automation.

The solution
A model where UI elements live in one place, tests stay clean, and changes are easy to manage.

That solution is the Page Object Model.

What Is Page Object Model (POM)?

The Page Object Model (POM) is a design pattern used in test automation frameworks that creates a separate class for each web page or screen of an application. Each page class contains:

  • Web elements
  • Page actions or methods
  • Page level logic

In simple terms, Page Object Model acts as a UI repository where each page is represented as an object.

Example Simplified

class LoginPage { WebElement usernameField; WebElement passwordField; WebElement loginButton;void login(String user, String pass) { usernameField.sendKeys(user); passwordField.sendKeys(pass); loginButton.click(); } }

Here, the LoginPage class contains:

  • All elements related to the login screen
  • The login action
  • A clean way to interact with the page

Your test script simply calls:

loginPage.login(“user123”, “abc123”);

This keeps your tests highly readable and easy to update.

Why Page Object Model Matters in Modern Test Automation

Page Object Model solves several key problems automation engineers face daily. Let’s explore its benefits.

Increased Maintainability

Changes to UI elements need updates only in one place, the corresponding page class.

If the login button ID changes, you update it only inside LoginPage.java instead of fixing dozens of scripts.

This saves hours of rework.

Better Code Reusability

Common actions like login, navigation, search, and logout become reusable methods.

Multiple test cases can reuse the same functions without rewriting code.

Example:

  • login as admin
  • login as user
  • login as guest

All use the same login method.

Enhanced Readability and Structure

POM promotes clean separation:

  • Page Classes control UI interactions
  • Test Scripts control business logic and validations

Your test scripts remain simple and expressive:

loginPage.login("admin", "admin123");
dashboard.verifyWelcomeText();

This makes your automation framework easier for new testers to understand, especially helpful for learners in quality analyst courses.

Reduces Code Duplication

Without POM, the same locators and actions appear every time across multiple scripts.

In Page Object Model, duplication is eliminated resulting in:

  • Cleaner code
  • Faster execution
  • Fewer failures

Easier Scalability for Large Applications

As projects grow, you simply keep adding page classes.

No need to redesign your entire framework.

This is why many companies prefer candidates who understand POM, especially those who completed a Testing software course or hands on QA training.

How Page Object Model Works: Structure Overview

A typical POM framework includes:

Page Classes

Each class represents a webpage or component.

Example:

  • LoginPage
  • HomePage
  • CartPage
  • ProfilePage

Each page contains:

  • Locators
  • Page actions
  • Helper functions

Test Classes

These hold the test logic, such as:

  • Validations
  • Navigation
  • Assertion checks

Example:

@Test
public void testValidLogin() {
    loginPage.login("validUser", "validPass");
    homePage.verifyDashboardLoaded();
}

Includes reusable components:

Utility or Helper Classes

  • Screenshot utility
  • Browser management
  • Reporting
  • Excel or CSV readers
  • Configuration files

Base Class

Handles framework level activities like:

  • WebDriver initialization
  • Browser setup
  • Test teardown
  • Global properties
  • Types of Page Object Models

POM is flexible and can be enhanced based on framework needs.Standard POM

Locators and methods are stored inside page classes.

Best for beginners.

POM with Page Factory Selenium

Uses annotations like @FindBy to simplify locator handling.

Example:

@FindBy(id=”username”) WebElement userName;

Benefits:

  • Lazy initialization
  • Improved readability
  • Faster execution

Page Object Model with Data Driven Framework

Test data comes from:

  • Excel sheets
  • CSV files
  • Databases
  • JSON

Perfect for real time applications where multiple input sets are needed.

Page Object Model with Hybrid Framework

Combines:

  • POM
  • Data driven
  • Modular approach
  • Keyword driven methods

This is used in large automation suites in enterprise applications.Real World Example: POM in Selenium

Let’s walk through a common scenario testing an ecommerce login.

LoginPage.java

public class LoginPage {
    
    @FindBy(id="email")
    WebElement emailInput;
    
    @FindBy(id="password")
    WebElement passwordInput;
    
    @FindBy(id="loginBtn")
    WebElement loginButton;

    public void login(String email, String password) {
        emailInput.sendKeys(email);
        passwordInput.sendKeys(password);
        loginButton.click();
    }
}

TestLogin.java

public class TestLogin extends BaseTest {

    @Test
    public void validateUserLogin() {
        LoginPage loginPage = new LoginPage(driver);
        loginPage.login("testuser@example.com", "pass123");
        Assert.assertTrue(homePage.isDashboardVisible());
    }
}

This is clean, maintainable, and reusable.

Common Mistakes Beginners Make with POM

Even though POM is simple, many beginners make avoidable mistakes.

Here are common pitfalls.

Mixing Test Logic with Page Logic

Page class is only for UI logic.
Test class is for business rules.

Never write assertions inside page classes.

Overcrowding Page Classes

Avoid adding too many unrelated methods.

Stick to the Single Responsibility Principle SRP.

Using Complex Locator Strategies

Use stable locators like:

  • ID
  • Name
  • CSS

Use XPath only when required.

Not Handling Dynamic Elements

Modern applications use:

  • AJAX
  • React
  • Angular

In such cases, use:

  • Explicit waits
  • Fluent waits
  • ExpectedConditions

This prevents flaky tests.

Best Practices to Follow in POM

To get the best out of POM, adopt these practices.

Keep Locators Private

Prevent direct access from test classes.

2. Use Meaningful Names

Bad:

btn1
txt2

Good:

loginButton
searchInput

Reuse Common Methods

Examples:

  • login
  • logout
  • searchProduct

Keep Page Methods Simple

Each method should perform one activity.

Use Consistent Naming Conventions

Helps teams collaborate easily.

Page Object Model

Why Page Object Model Is Essential for Future QA Professionals

Automation is no longer optional. It is a necessity.

Companies expect testers to handle:

  • Selenium
  • API automation
  • CI CD
  • Version control
  • GitHub
  • Cloud execution BrowserStack or Sauce Labs

Understanding POM is a must have skill for:

  • QA Engineers
  • Automation Testers
  • SDETs
  • Test Leads

Enrolling in well structured quality analyst courses or a comprehensive Testing software course gives you hands on experience in POM and modern automation frameworks.

Where POM Fits in a Complete Automation Framework

POM integrates well with:

  • Selenium WebDriver
  • TestNG
  • JUnit
  • Cucumber BDD
  • Maven or Gradle
  • Jenkins CI CD pipeline

In BDD frameworks, POM supports step definitions to keep code clean and organized.

Sample Framework Folder Structure

src/main/java
    pages
        LoginPage.java
        HomePage.java
        ProfilePage.java
    utils
        DriverFactory.java
        ConfigReader.java
        ExcelUtil.java
    base
        BaseTest.java

src/test/java
    testcases
        LoginTest.java
        LogoutTest.java
    resources

This is the structure used in professional projects and QA team environments.

Advantages of Using POM in Agile and CI CD

Faster Test Execution

Scripts run smoothly with fewer failures.

Low Maintenance Across Sprints

UI changes don’t break the entire suite.

Developer Testers Collaboration

Developers and testers can work together because:

  • Code is cleaner
  • Framework follows design patterns
  • Easier code reviews

High ROI in Test Automation

Companies invest in automation to reduce:

  • Time
  • Cost
  • Human error

POM delivers on these goals.

POM in BDD Automation Frameworks Cucumber

In Cucumber, we write:

Given user enters valid login credentials
When user clicks login
Then dashboard should appear

POM stores the locators and actions while step definitions call page methods.

This avoids repetition and keeps code clean.

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.

Conclusion

The Page Object Model is more than just an automation design pattern. It is the backbone of scalable, maintainable, and future ready test automation. Whether you are just starting your journey through upgrading your skills in a QA Testing software course, mastering POM makes you a more efficient and industry ready automation professional.

POM helps testers:

  • Reduce maintenance
  • Improve test stability
  • Enhance reusability
  • Scale automation easily
  • Build cleaner frameworks

As automation testing continues to evolve, Page Object Model remains a must have skill for QA careers.

Share this article

Enroll Free demo class
Enroll IT Courses

Enroll Free demo class

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.

Join Free Demo Class

Let's have a chat