·

8 min

Page Object Model: Structure, Example and Limits for UI Tests

Roman Kirchmeier - Autemos

Roman Kirchmeier - Autemos

Test architect sketches a page object model of linked pages on a whiteboard while a developer compares it on screen

The Page Object Model (POM) is a design pattern for UI tests that wraps each page or page section of a web application in its own class. In an industrial case study, repairing a test suite after a software upgrade took 43 minutes instead of 124 (Leotta et al., 2013). A bank login with a transfer form needs five page objects and one component; for short-lived prototypes and pure API tests, POM doesn't pay off. For the bigger picture, see the UI testing guide.

TL;DR: A page object is a class that wraps a page or component of your app: locators and actions go inside, assertions stay in the test. Methods return the next page object. In a case study with 25 test cases, repairs after an upgrade took 43 minutes instead of 124. When writing small suites, the extra effort can outweigh the benefit (Leotta et al. 2020).

Page Object Model in three layers: test with flow and assertions, page object with locators and actions, web app with pages and elements

Figure 1: The test calls business methods; the page object wraps locators and actions.

What is the Page Object Model?

The Page Object Model is a test automation design pattern that separates operating a user interface from the test flow. The Selenium docs define it this way: “A page object is an object-oriented class that serves as an interface to a page of your AUT” (Selenium, 2026). AUT stands for application under test.

For Martin Fowler, a page object puts a business-level API in front of an HTML page: “A page object wraps an HTML page, or fragment, with an application-specific API” (Martin Fowler, 2013). The test calls methods such as loginAs(). It never touches the HTML. Simon Stewart, quoted by Fowler, puts it more bluntly: “If you have WebDriver APIs in your test methods, You're Doing It Wrong.”

How do you build a Page Object Model step by step?

You build a Page Object Model in six steps, from listing the pages to handing page objects to tests through fixtures. You need a framework such as Playwright or Selenium; the Selenium vs. Playwright comparison helps you pick one.

Six steps to a Page Object Model: list pages, wrap locators, business methods, return next page, return values, use fixtures

Figure 2: Building a Page Object Model in six steps.

  1. Identify pages and components. Walk the user flow and list every page and recurring area, such as login, transfer form and header menu. Each entry becomes a class.

  2. Move locators into the class. Selectors stay private inside the page object, never in the test. Prefer roles and test IDs; the article on locator strategies for stable tests explains the order.

  3. Write business-level methods. A method bundles something the page does, such as loginAs(contract, password), instead of mirroring single clicks. Selenium calls public methods “the services that the page or component offers”.

  4. Define return values. If an action leads to a new page, the method returns the next page object. If the user stays on the page, it returns itself.

  5. Return values for checks. The page object hands back text or state, and the test compares it.

  6. Provide page objects through fixtures. In Playwright Test, fixtures hand ready-made page objects to each test; the docs show this with todoPage and settingsPage (Playwright fixtures).

Playwright's official POM examples use page.locator() with CSS. Using role locators such as getByRole inside page objects is our recommendation, derived from Playwright's locator page: “We recommend prioritizing role locators to locate elements” (Playwright locators).

What does a page object for a bank login and transfer look like?

A POM for the login and transfer flow of a banking web app has five page objects and one page component. Each method returns the page object of the next page or itself, and values for checks come back as text. Names and fields are constructed.

Class

Locator (example)

Method

Returns

LoginPage

getByLabel('Contract number'), getByLabel('Password'), getByRole('button', name 'Log in')

loginAs(contract, password)

DashboardPage

LoginPage

same fields

loginExpectingError(contract, password)

LoginPage (itself)

LoginPage

getByRole('alert')

errorMessage()

Text

DashboardPage

NavigationComponent (page component object)

openTransfer()

TransferPage

TransferPage

getByLabel('Recipient IBAN'), getByLabel('Amount'), getByLabel('Message')

fillTransfer(iban, amount, message)

TransferPage (itself)

TransferPage

getByRole('button', name 'Continue')

continueToReview()

ReviewPage

ReviewPage

getByTestId('transfer-summary')

summaryText()

Text

ReviewPage

getByLabel('TAN'), getByRole('button', name 'Confirm')

confirmWithTan(tan)

ReceiptPage

ReceiptPage

getByTestId('payment-reference')

referenceNumber()

Text

LoginPage has two methods for the same action, one for success and one for the error message. That follows Selenium: “Different results for the same action are modelled as different methods.” To confirm the review page shows the right IBAN and CHF 250.00, summaryText() supplies the text.

Which rules apply to page objects?

The main rule for page objects is that they don't check anything. Selenium states: “Page objects themselves should never make verifications or assertions” (Selenium, 2026). The only allowed check sits in the constructor and confirms the expected page has loaded. Fowler writes “I favor having no assertions in page objects” and accepts checks of page invariants.

Four rules for page objects: no assertions, load check allowed in the constructor, one result per method, model components once

Figure 3: Four rules for page objects based on the Selenium docs.

Why keep assertions out of page objects?

Assertions inside a page object tie the class to a single test case. If openTransfer() itself checks that the account is active, no other test can run the blocked-account case. Checks in the test show readers what's expected. For the load check, Selenium offers the LoadableComponent base class with load and isLoaded (Selenium design strategies).

What are page component objects?

Page component objects are classes for distinct parts of a page that appear in several page objects. Selenium describes them as objects that “represent discrete chunks of the page and can be included in page objects”. You model the header menu or account picker once and use it in DashboardPage and TransferPage. Fowler suggests the name “panel object” for them.

What does research say about the benefit of POM?

One industrial case study shows a maintenance benefit for POM after a UI change, and a family of experiments shows extra effort when writing the tests. In the case study at eXact learning solutions in Italy, a team repaired two equivalent Selenium suites of 25 test cases each after an upgrade. With page objects, it took 43 minutes instead of 124 (Leotta et al., 2013).

Leotta et al. 2013 case study with 25 test cases: repair time 124 vs. 43 minutes, modified lines of code 90 vs. 11

Figure 4: With page objects, repair time after an upgrade fell by 65 % (Leotta et al. 2013).

Metric (Leotta et al. 2013)

Without page objects

With page objects

Total repair time

124 minutes

43 minutes

Modified lines of code (LOC)

90

11

Effort for test case 1

Baseline

8 minutes longer

That's 81 minutes, or 65.32 %, less. Only the first test case cost more, since three page objects had to change. Every test case after that went faster. The data comes from a single case study with a single upgrade.

The family of experiments shows the limit. In their setting, the benefits of page objects didn't offset the extra development effort. Test development only gets more efficient with page objects “when the test suite to be developed is at least 10x larger” (Leotta et al., 2020). For other ways to cut upkeep, read about reducing test maintenance with AI.

What criticism and alternatives exist?

The sharpest criticism of POM comes from Cypress, and the main alternatives are App Actions and the Screenplay pattern. The official Cypress docs list “Anti-Pattern: Sharing page objects, using your UI to log in, and not taking shortcuts” (Cypress docs). Their recommendation is to log in programmatically and take control of the application's state.

Gleb Bahmutov goes further on the Cypress blog: “In this post I argue that page objects are a bad practice.” He proposes App Actions, where tests dispatch actions straight to the application's internal logic (Cypress blog, vendor blog, 2019). That needs access to the app code, which teams testing purchased banking software usually don't have.

The Screenplay pattern models tests through actors who use abilities to perform tasks and interactions (Serenity/JS). Serenity/JS says it brought the pattern to JavaScript in 2016. We haven't found a peer-reviewed study that compares Screenplay and POM directly.

Approach

Core idea

Source

Requires

POM

One class per page wraps locators and actions

Selenium docs, Fowler

A UI framework

Page component objects

Classes for recurring page parts

Selenium docs, Fowler (“panel object”)

Existing page objects

Screenplay

Actors use abilities for tasks and interactions

Serenity/JS

More concepts than POM

App Actions

Tests call the app's internal logic directly

Cypress blog (vendor)

Access to the app code

When should you skip POM?

Skip POM when the suite is small and short-lived, or when there are no pages to wrap.

  • The suite has few tests and a short life, such as a prototype.

  • You test at component level, where there are no pages to wrap.

  • The test checks logic behind the UI. An API test doesn't need page classes.

  • The page object would hold one method with one click. A helper function is enough.

  • Every test builds its state through the UI. Create test data through the API first, then write page objects.

How does Autemos generate page objects?

The Autemos AI Recorder turns a recorded or described test flow into the visual workflow, the page objects and the code in real time. Autemos is AI-assisted software for functional test automation across web, mobile, API and desktop. You can record by clicking, with no plugins, or use the AI chat with natural language, Jira tickets or test case text. The team has to approve every AI-generated step before it runs.

How much generated page object code works without edits has been measured on a different tool. With APOGEN, a clustering-based generator from 2016, about 75 % of the generated code could be used as-is (Stocco et al., 2016). The remaining quarter couldn't. So generated page objects need human review.

Autemos exports web tests as Playwright code (Java or TypeScript) and mobile tests as Appium code (Java), synced with Git. The exported code runs without Autemos; the code generation page has the details. If a locator breaks after a release, self-healing locators take over. Autemos doesn't run load or security tests. For choosing browsers, see the guide to cross-browser testing.

Frequently asked questions

What's the difference between a page object and the Page Object Model?

A page object is the single class for one page or component, and the Page Object Model is the pattern for building a whole test suite from such classes.

Do assertions belong in a page object?

No, the Selenium docs say page objects should never make assertions themselves. The only exception is the load check in the constructor; Martin Fowler accepts checks of invariants too.

Does POM work with Playwright?

Yes, Playwright documents POM for TypeScript and Java, and its fixtures docs show how page objects get into tests.

How many tests do you need before POM pays off?

There's no fixed number. Leotta et al. (2020) found that page objects make test development more efficient only once the suite is at least 10 times larger than in their experiments. For maintenance, the 2013 case study showed 43 instead of 124 minutes of repair time with just 25 test cases.

Is the Screenplay pattern better than POM?

There's no solid evidence; we haven't found a peer-reviewed comparison. In our view, Screenplay fits large suites with many roles. POM needs fewer concepts.

Conclusion

The Page Object Model wraps each page in a class with locators and actions, and methods return the next page object. The payoff shows up in maintenance: in the Leotta et al. case study, repair time after an upgrade fell from 124 to 43 minutes. In experiments, though, the benefit didn't offset the extra effort of writing small suites. Start with the pages on your most important path and add page component objects for recurring areas. Generated page objects save typing and need review. If you'd like to see how Autemos generates page objects from a recording and exports them as Playwright code, book a demo.

Experience Autemos. In just 30 minutes.

See for yourself and experience how simple, flexible, and controlled modern test automation can be today.

Social Connect

© 2026 Autemos. A product of selementrix GmbH.

Experience Autemos.
In just 30 minutes.

See for yourself and experience how simple, flexible, and controlled modern test automation can be today.

Social Connect

© 2026 Autemos. A product of selementrix GmbH.

Experience Autemos.
In just 30 minutes.

See for yourself and experience how simple, flexible, and controlled modern test automation can be today.

Social Connect

© 2026 Autemos. A product of selementrix GmbH.