Page Object Model in Test Automation: When It Helps and When It Hurts
The Page Object Model (POM) is the most widely used design pattern in UI test automation: each page or component gets a class that knows how to interact with it, so tests can focus on what they check. Used well, it removes duplication and makes tests easy to read. Used badly, it creates a second, harder-to-maintain codebase.
The basic idea
Without page objects, locators and steps are repeated across tests:
When the coupon field's label changes, you update one line, not twenty tests.
Guidelines that keep it healthy
Model user intent, not every element.applyCoupon(code) is better than exposing couponInput and applyButton separately.
Keep assertions in tests. Page objects describe how to interact; tests decide what's correct. (Exposing locators like total for tests to assert on is fine.)
Return data or the next page, not booleans. Avoid methods like isCouponApplied(), which hide what's being checked.
Compose components. A Header or ProductCard component object can be reused across pages.
Avoid deep inheritance.BasePage → ShopPage → CartPage → DiscountCartPage becomes a maze. Prefer composition.
Common failure modes
God objects: a 1,500-line page class nobody wants to touch. Split by component.
Mirroring the DOM: one method per element turns page objects into a locator dictionary with extra steps.
Hidden waits and retries inside page methods mask real timing problems.
Premature abstraction: creating page objects before you have three tests that need them.
Lighter alternatives
You don't always need classes:
Helper functions:await addToCart(page, 'Ceramic mug'). Simple, and often enough for small suites.
Fixtures (Playwright): inject ready-made page objects or pre-signed-in pages into tests:
// fixtures.ts
import { test as base } from '@playwright/test';
import { CartPage } from './pages/cart-page';
export const test = base.extend<{ cart: CartPage }>({
cart: async ({ page }, use) => {
const cart = new CartPage(page);
await cart.open();
await use(cart);
},
});
Screenplay pattern: actors performing tasks and asking questions. It's more structure, and it pays off in very large suites with many user roles.
How to decide
Suite size
Suggested approach
A handful of tests
Plain tests, maybe a few helpers
Dozens of tests across several pages
Page or component objects + fixtures
Hundreds of tests, many roles and teams
Component objects, fixtures, possibly Screenplay
Refactor toward patterns when duplication hurts, not in anticipation of it.
Test design comes first
Patterns make tests maintainable, but they don't decide what to test. Start from risks and real bugs: explore an app in QAUnlocked Practice Labs, list the defects you found, and design page objects around the flows that matter, like cart, coupons and checkout.
An honest comparison of the three most popular browser automation tools, covering architecture, language support, browsers, speed, debugging and ecosystem, and which to pick for your situation.
Flaky tests destroy trust in automation. The most common causes (timing, shared state, order dependence, environments, brittle locators), how to diagnose them, and fixes that actually work.
Most broken UI tests break on locators. A practical priority order for locators (role, label, text, test ID, CSS), with examples in Playwright and Cypress and the anti-patterns to avoid.
We use cookies
We use cookies to keep you signed in and to understand how our site is used.
Be the first to comment.