New data from 1,500+ QA pros: The 2025 State of Software Quality Report is live
DOWNLOAD YOUR COPY
All All News Products Insights AI DevOps and CI/CD Community

Page Object Model In Automation Testing: A Complete Guide

Learn what Page Object Model (POM) is in automation testing, its benefits, and how it helps create maintainable, reusable test scripts.

Hero Banner
Smart Summary

The Page Object Model (POM) stands as a foundational design pattern in automation testing, enabling the creation of highly maintainable, reusable, and scalable test scripts. It achieves this by abstracting UI elements and interactions into dedicated page classes, ensuring test logic remains clean and robust against application interface changes. Embracing this pattern streamlines test development and significantly enhances automation project efficiency.

  • Ensure Test Script Robustness: Centralize UI element locators and associated actions within dedicated page classes to dramatically improve test script maintainability and reusability. This isolation means UI changes only require updates to the relevant page object, preserving test functionality across your suite.
  • Construct a Scalable Framework: Build your POM framework by separating concerns into distinct Page classes for UI interactions, Test classes for core business logic, and a Base class for shared setup. Utilize Selenium's Page Factory to simplify element initialization, fostering a clean, organized, and scalable automation structure.
  • Refine Your POM Implementation: Adhere to best practices by keeping assertions out of page objects and returning new page objects when actions lead to navigation, enhancing clarity and modularity. For complex UIs, employ component objects to manage repeating sections, further boosting reusability and maintainability.
Good response
Bad response
|
Copied
>
Read more
Blog / Insights /
Page Object Model In Automation Testing: A Complete Guide

Page Object Model In Automation Testing: A Complete Guide

QA Consultant Updated on

Page Object Model in Automation Testing is one of the most popular design patterns for building maintainable and scalable test scripts. It is widely used by QA teams who want to write clean, reusable, and easy-to-maintain code when automating tests for web applications.

The idea is simple yet powerful. Instead of mixing locators and actions directly in test scripts, the page object pattern in Selenium and other frameworks groups all the elements and actions of a page inside a dedicated class. This makes your test cases shorter, cleaner, and easier to update whenever the UI changes.

In this guide, you will learn:

  • What the Page Object Model (POM) is and why it matters
  • The benefits of page object model for large automation projects
  • How to implement a POM framework for automation testing step by step
  • Best practices to follow for POM design in test automation
  • How to use POM effectively with Katalon Studio and Selenium

Let's get started!

What is the Page Object Model (POM)?

The Page Object Model in Automation Testing is a design pattern that creates an object-oriented class for each web page in your application. Each class contains locators for UI elements and methods to perform actions on those elements. This structure keeps the test logic separate from the page structure, which makes the code easier to read and maintain.

The POM framework for automation testing is widely used in Selenium test automation. By using this model, teams can avoid duplication of code, make test scripts more reusable, and improve overall code quality. It is a foundation for building a scalable test automation framework that supports rapid development and frequent UI updates.

Here is a simple example to show how the page object pattern in Selenium improves test scripts. Without POM, a test script might include locators and actions directly in the code. With POM, all locators and actions are stored in a dedicated page class, and the test script calls simple high-level methods:

Without POM (Selenium Java)
WebDriver driver = new ChromeDriver();
driver.get("https://example.com/login");
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.id("password")).sendKeys("pass");
driver.findElement(By.id("loginButton")).click();

Now see how the same test looks when using POM design in test automation. The locators and actions live inside a LoginPage class. The test script only calls a simple method, which improves readability and maintainability.

With POM (Selenium Java)
LoginPage loginPage = new LoginPage(driver);
loginPage.loginAs("user", "pass");

This simple change shows the benefits of page object model for large test suites. It keeps code clean and easier to manage. When the login page changes, you only update the LoginPage class. All tests that use this class will continue to work without any other changes.

Why use Page Object Model in Test Automation?

The Page Object Model in Automation Testing is a proven way to make automated tests more efficient. It is especially helpful for teams that work with fast-changing UIs or need to run a large number of tests frequently. The POM framework for automation testing gives structure to test code so that it stays clean and reusable.

By placing all element locators and actions inside a page class, you improve reusability. Each page class serves as a single source of truth for that page. Test scripts become shorter because they only call methods from the page class rather than writing the same steps again and again.

POM design in test automation also improves maintainability. When a UI element changes, you only update the locator in the page class. All tests that use that page class will continue to run without further changes.

The page object pattern in Selenium is highly scalable. It works very well for large projects with many pages and complex user flows. As your test suite grows, you can add more page classes and component objects without rewriting old tests.

Example of Page Object Model in E-commerce

For example, imagine an eCommerce app with more than thirty test cases for the checkout process. The “Place Order” button changes its locator after a new release.

With the page object model, you only update the locator inside the CheckoutPage class. All related test cases will still run successfully without any extra edits.

Core Components of Page Object Model

The Page Object Model in Automation Testing is made up of several core components. Each of these plays a specific role in keeping test code organized and easy to maintain. When combined, they form a POM framework for automation testing that supports scalability and clean test design.

1. Page classes

Page classes represent individual web pages in your application. They store element locators and provide methods to interact with those elements. For example, a LoginPage class might include methods like setEmail, setPassword, and clickLogin. These methods hide low level details from the test script and improve code reusability.

2. Test classes

Test classes contain the actual test cases. They call methods from the page classes to perform actions. A test class for login might create a new LoginPage object and call loginAs("user", "pass"). This separation makes test cases more readable and focused on business logic rather than UI details.

3. Base class

The base class is an optional shared class that handles setup and teardown tasks. It usually initializes the WebDriver, sets browser configurations, and closes the browser after test execution. Test classes can extend the base class so that they automatically inherit these settings. This reduces duplicate code across tests.

4. Page Factory

Page Factory is a Selenium feature that helps initialize elements in page classes. By using annotations like @FindBy, you can define element locators once and let Selenium handle initialization. Page Factory simplifies the POM design in test automation and makes page classes easier to manage.

Together, these components form the structure of the page object pattern in Selenium. They allow you to create a maintainable test automation framework that can grow with your application.

Implementation of POM (Step-by-Step)

The best way to understand the Page Object Model in Automation Testing is by looking at a real example. Below is a simple Gmail login test built with the page object pattern in Selenium. Each step shows how to create clean and maintainable code that follows POM design in test automation.

Step 1: Create the TestBase class

The TestBase class is responsible for setting up the WebDriver, configuring the browser, and closing it after tests run. This avoids repeating setup code in every test class.

TestBase.java
public class TestBase {
    public WebDriver driver;

    @BeforeMethod
    public void setUp() {
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://mail.google.com");
    }

    @AfterMethod
    public void tearDown() {
        driver.quit();
    }
}

Step 2: Create the GmailLoginPage class

This page class contains locators and methods for interacting with the Gmail login page. Using @FindBy annotations with Page Factory makes the code cleaner.

GmailLoginPage.java
public class GmailLoginPage {
    WebDriver driver;

    @FindBy(id = "identifierId")
    WebElement emailField;

    @FindBy(name = "password")
    WebElement passwordField;

    @FindBy(id = "identifierNext")
    WebElement nextButton;

    public GmailLoginPage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void setEmail(String email) {
        emailField.sendKeys(email);
    }

    public void setPassword(String password) {
        passwordField.sendKeys(password);
    }

    public void clickNext() {
        nextButton.click();
    }

    public GmailHomePage loginAs(String email, String password) {
        setEmail(email);
        clickNext();
        setPassword(password);
        clickNext();
        return new GmailHomePage(driver);
    }
}

Step 3: Create the GmailLoginTest class

The test class extends TestBase to inherit setup and teardown logic. It creates a GmailLoginPage object and calls the loginAs method for a clean and simple test.

GmailLoginTest.java
public class GmailLoginTest extends TestBase {
    @Test
    public void verifyLogin() {
        GmailLoginPage loginPage = new GmailLoginPage(driver);
        GmailHomePage homePage = loginPage.loginAs("user@gmail.com", "password123");
    }
}

Step 4: Extend for GmailHomePage class

The GmailHomePage class can be created to represent the landing page after login. It allows you to chain page objects so that each page action returns the correct page class.

GmailHomePage.java
public class GmailHomePage {
    WebDriver driver;

    public GmailHomePage(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public String getLoggedInUser() {
        return driver.getTitle();
    }
}

This step by step example shows how the POM framework for automation testing creates clear and reusable code. Each class has a single responsibility, which improves readability and makes future maintenance easy.

Advantages of Page Object Model

The Page Object Model in Automation Testing provides many benefits that make test automation easier to manage. It gives teams a reliable structure that can grow with the application. Below are the main advantages of using the page object pattern in Selenium and other frameworks.

1. Reusability

POM design in test automation increases reusability because each page class holds all locators and actions for that page. When you update a locator in the page class, all dependent tests automatically use the new locator. This saves time and reduces effort in maintaining large test suites.

2. Maintainability

The benefits of page object model include better maintainability. If the UI changes, you only need to update the affected page class. Test cases stay the same and continue to run as expected. This approach is very helpful for projects with frequent UI updates.

3. Readability and cleaner test code

The page object model best practices encourage keeping test scripts focused on business logic. Testers write short and clear scripts because they just call high level methods like loginAs or addToCart. The low level details stay hidden inside page classes. This improves readability for the whole team.

4. Scalability for CI/CD

A POM framework for automation testing works well in CI/CD pipelines. It keeps test scripts modular and version controlled. Teams can add more pages and features without changing existing tests. This structure supports faster releases and more reliable automated testing.

Page Component Objects

The Page Object Model in Automation Testing can be extended to handle complex pages. Many modern web applications have pages with multiple repeating sections. By creating component objects, you can model these sections as reusable parts of a page class.

For example, a ProductsPage can have many Product components. Each Product component contains its own locators and actions, such as getting the name or price and adding the product to the cart. This composition makes the POM framework for automation testing more modular and easier to scale.

ProductComponent.java

public class ProductComponent {
    WebDriver driver;
    WebElement productElement;

    public ProductComponent(WebDriver driver, WebElement productElement) {
        this.driver = driver;
        this.productElement = productElement;
        PageFactory.initElements(driver, this);
    }

    @FindBy(className = "product-name")
    WebElement name;

    @FindBy(className = "product-price")
    WebElement price;

    @FindBy(className = "add-to-cart")
    WebElement addToCartButton;

    public String getName() {
        return name.getText();
    }

    public String getPrice() {
        return price.getText();
    }

    public void addToCart() {
        addToCartButton.click();
    }
}

This page object pattern in Selenium lets you build test scripts that interact with specific components on a page. It increases reusability and keeps page classes well structured. The benefits of page object model become even greater as your application grows and more UI components are added.

Best Practices for Page Object Model

Following best practices helps you get the most out of the Page Object Model in Automation Testing. These tips make your POM framework for automation testing more robust, reusable, and easier to maintain.

  • Keep assertions out of page objects. Page classes should only contain locators and actions. Tests should handle verification logic so that page objects stay focused on interactions only.
  • Avoid exposing WebDriver directly in page classes. Instead of returning the driver object, provide methods to perform actions. This makes your page classes easier to use and reduces dependency on the driver in your test scripts.
  • Return new page objects when navigation leads to a new page. If an action on one page takes you to another page, return the corresponding page object. This makes test scripts easier to read and shows the flow between pages.
  • Use meaningful method names like loginAs(user, pass). Clear method names make test scripts more readable. They describe the purpose of the action instead of focusing on technical steps like typing text or clicking buttons.
  • Keep locators in one place. Store locators only in their page class. Avoid duplicating locators across multiple classes to make maintenance easier when UI changes happen.
  • Use composition for page sections. Break down complex pages into smaller component objects. This structure helps when building reusable test scripts and makes the POM design in test automation more flexible.

Page Object Model vs. Non-POM Testing

The Page Object Model in Automation Testing creates cleaner and more maintainable test scripts compared to non POM testing. The table below shows the key differences between the two approaches.

Aspect Non POM Testing Page Object Model
Structure Locators and actions mixed inside test scripts Locators and actions stored inside page classes
Maintainability Updating UI changes requires editing every affected test Updating one page class applies to all dependent tests
Code duplication High because steps are repeated in many test cases Low because actions are centralized in page classes
Readability Tests include technical details that make scripts longer Tests focus on business logic with short clear methods
Scalability Harder to scale as the number of test cases increases Easier to scale by adding more page classes and methods

This comparison shows how the benefits of page object model make it the better choice for building a scalable and maintainable automation framework.

How to Use POM with Katalon Studio

Katalon Studio supports the Page Object Model in Automation Testing through its built in Object Repository, custom keywords, and flexible scripting features. It makes creating a POM framework for automation testing easier for both beginners and experienced testers.

Follow these steps to implement the page object pattern in Katalon Studio:

  • Define page classes in script view. Create Groovy or Java classes in the script view to represent each page. Add methods that perform actions like entering text, clicking buttons, or validating values.
  • Map UI elements via the Object Repository. Use the Object Repository to store element locators. Katalon provides an easy interface to capture and manage objects without writing complex code.
  • Use custom keywords for reusable actions. Create custom keywords to model actions as methods. These keywords can be used across multiple test cases to reduce duplication and improve reusability.
  • Call methods from test cases. In your test cases, simply call the page object methods or custom keywords. This keeps scripts short, modular, and easy to understand.

Katalon logoKatalon is an all in one automation testing tool. With a Katalon license, you can:

  • Write UI and API test cases for web, desktop, and mobile apps using Katalon's pre built automation testing frameworks.
  • A library called Object Repository to centralize all of your UI elements to access quickly while writing tests. There is also an Object Capture utility to quickly capture the locator of any web elements.
  • Built in test data management, data driven testing, and BDD testing.
  • Run tests on your local machine, remotely, on cloud, with emulators or simulators, or on a private device that you have. Thousands of environment combinations are available.
  • Run tests in parallel from the Command Line Interface with Katalon Runtime Engine. This significantly speeds up test execution.
  • Integrate Katalon tests into your existing CI or CD tools to automatically trigger tests when code is merged.
  • Schedule test execution, manage their status, and generate detailed test reports including screenshots, videos, and snapshots.

Katalon is one of the first AI powered automation testing tools. Notable features include automatic test maintenance and AI powered regression testing with TrueTest. TrueTest analyzes user behavior in production and generates test cases automatically based on insights.

Create automated tests easier with Katalon

📝 If you want a more customized automation testing tool for your team, you can request a demo from Katalon in this form.

Conclusion

The Page Object Model in Automation Testing is the foundation for creating maintainable and scalable UI test scripts. It keeps test code clean, reusable, and easy to update when applications grow and interfaces evolve. Teams that follow the page object pattern in Selenium and similar frameworks save time and improve test reliability.

Katalon Studio makes it easier to implement a POM framework for automation testing. With its Object Repository, custom keywords, and CI or CD integrations, Katalon provides a complete solution for building structured and efficient test automation. Using these features helps teams get the full benefits of page object model while delivering high quality applications faster.

Ask ChatGPT
|
Vincent N.
Vincent N.
QA Consultant
Vincent Nguyen is a QA consultant with in-depth domain knowledge in QA, software testing, and DevOps. He has 10+ years of experience in crafting content that resonate with techies at all levels. His interests span from writing, technology, building cool stuff, to music.
on this page
Click