Framework Design

Page Object Model (POM)

Learning Outcome

4

Improve test readability and reduce code duplication.

3

Create reusable and maintainable page classes.

2

Separate test logic from UI interaction code.

1

Understand the purpose and structure of POM.

5

Apply POM with Selenium and update tests easily when UI changes. 

 

Recall

Page Object Model (POM)

To understand POM, you need to revise the topics like

Object-Oriented Programming (OOP)

Programming Language Basics

Selenium WebDriver Fundamentals

HTML & DOM Structure

Classes, objects, methods, encapsulation, and inheritance

Java / Python / any language used for automation

Locators (id, xpath, css), actions (click, sendKeys), waits

Understanding web elements and how they are structured

Test Automation Basics

Basic Framework Knowledge

Test cases, assertions, test execution flow

Familiarity with tools like TestNG / PyTest (optional but helpful)

These topics will make learning POM much easier and more effective.

Think of Page Object Model (POM) like ordering food in a restaurant:

 

Menu (Page Class):
The menu lists all available dishes (elements and actions on a webpage).

Waiter (Methods in Page Class):
You don’t go into the kitchen yourself—you tell the waiter what you want. Similarly, tests don’t directly interact with UI elements; they call methods

Analogy to Understand Need of POM

Kitchen (UI / Web Page):
he actual work (clicking buttons, entering text) happens behind the scenes.

Customer (Test Script):
You simply place an order (call methods) without worrying about how the food is prepared.

How this relates to POM:

You separate responsibilities (customer ≠ kitchen)

You reuse the same menu/waiter for multiple orders (reusability)

If something changes (recipe/UI), only the kitchen/menu needs updating—not the customer’s behavior

This way, POM keeps your test code clean, organized, and easy to maintain, just like a well-managed restaurant system

Why use Page Object Model (POM)?.

 

POM is used to make test automation:

 Easier to maintain
 More readable
 Reusable
 Scalable
 Less prone to errors

Without POM, automation scripts become:

 Repetitive
 Hard to maintain
 Difficult to update when UI changes

What is Page Object Model (POM)?

Page Object Model (POM) is a design pattern used in test automation where each web page of an application is represented as a separate class.

Each page class contains:

Web elements (locators)

Methods (actions on those elements)

The main idea is to separate test logic from UI interaction logic.

Structure of  POM

Page Classes (Page Objects)

Each page of application is a class:

 

  • LoginPage

  • HomePage

  • DashboardPage

They contain:

 

  • Locators (elements)

  • Methods (actions)

Example:

 

  • enterUsername()

  • clickLogin()

  • getTitle()

Test Classes

 

Test classes contain:

 

  • Test cases

  • Assertions

  • Test flow (no direct UI handling)

They call methods from page classes.

 

Object Repository (Inside Page Classes)

 

 

Stores UI elements like:

  • ID

  • XPath

  • CSS selectors

AutomationFramework/

 

 

├── src/main/java

│   ├── pages/

│   │   ├── LoginPage.java

│   │   ├── HomePage.java

│   │   └── DashboardPage.java

│   │

│   ├── utilities/

│   │   ├── WebDriverUtility.java

│   │   ├── ConfigReader.java

│   │   └── ScreenshotUtility.java

 

├── src/test/java

│   ├── tests/

│   │   ├── LoginTest.java

│   │   └── HomeTest.java

├── src/main/resources

│   ├── config.properties

│   ├── testdata.json

├── drivers/

├── reports/

├── testng.xml

└── pom.xml

 

Working of POM (Flow)

 

 

  1. Test script calls page class method

2. Page class interacts with web elements

3. Selenium performs actions on browser


4. Result is validated in test class

Example of POM

Page Class (LoginPage )

  • username field

  • password field

  • login button

Methods:

 

  • enterUsername()

  • enterPassword()

  • clickLogin()

Test Class

 

  • Create object of LoginPage

  • Call methods in sequence

  • Verify result

Resusability
        Same methods can be used in multiple tests.

Advantages of POM

 

Maintainability
         If UI changes, update only page class.

Readability
        Test cases are clean and easy to understand.


Reduced Code Duplication

        No repeated locators or actions.

 

Scalability
      Easy to extend for large projects.

 

Better Collaboration

       Developers and testers can work efficiently.

 

 POM with Selenium

 

POM is widely used with:

 

  • Selenium WebDriver

  • TestNG / JUnit / PyTest

  • Maven / Gradle frameworks

It helps build:

 

 

  • Hybrid frameworks

  • Data-driven frameworks

  • Scalable automation suites

Think of an online shopping website:

 

Example

HomePage → Search products

ProductPage → View product details

CartPage → Add/remove items

CheckoutPage → Payment process

Each page has its own class, and tests just call actions like:

 

  • searchProduct()

  • addToCart()

  • placeOrder()

Summary

4

3

2

1

WebElements represent HTML elements on a web page in Selenium.

5

Check element states: displayed, enabled, selected.

 

Perform actions: click, type, clear, submit.

1

POM is a Selenium design pattern where each web page is a separate class

2

It stores locators and actions inside page classes

3

Test scripts use page methods instead of direct element handling

4

Improves code reusability, readability, and maintainability

5

Reduces code duplication and makes UI changes easier to handle

Quiz

What is the main purpose of the Page Object Model (POM)?

A. To increase execution time

B.To separate test logic from UI interaction

C.To write only test data

D. To avoid using Selenium

 

Quiz - Answer

What is the main purpose of the Page Object Model (POM)?

A. To increase execution time

C.To write only test data

D. To avoid using Selenium

 

B.To separate test logic from UI interaction