SoftwareTestPilot
Automation TestingPublished: 13 min read

Page Object Model (POM) — Complete Guide with Code (2026)

The Page Object Model explained for 2026 with runnable Playwright and Selenium code. When POM helps, when it hurts, the App Actions alternative, and how to migrate a 200-test suite without breaking CI.

Avinash Kamble
Founder & QA Engineer at SoftwareTestPilot
Reviewed by Priyanka G.
Share:XLinkedInWhatsApp
Page Object Model complete guide 2026 — Playwright and Selenium code samples.
Page Object Model complete guide 2026 — Playwright and Selenium code samples.

Last updated 2026-07-20 · 13 min read · By Avinash Kamble, reviewed by Priyanka G.

Page Object Model (POM) is the default framework pattern taught in every course — and the pattern most teams misuse. Applied well, it cuts locator churn by 60%; applied blindly, it doubles maintenance. This guide is the 2026 version with runnable Playwright and Selenium code, plus when to pick App Actions instead.

Key takeaways

  • Canonical POM in Playwright and Selenium (with types).
  • The three POM anti-patterns that kill maintainability.
  • When App Actions beats POM — with a worked example.
  • How to migrate a 200-test suite to POM in three sprints.

1. Why POM exists

POM encapsulates a page's locators and actions in one class so tests read like user intent, not selectors. When the DOM changes, one file changes — not fifty.

2. Playwright POM — canonical implementation

// pages/LoginPage.ts
import { Page, Locator, expect } from '@playwright/test';

export class LoginPage {
  readonly page: Page;
  readonly email: Locator;
  readonly password: Locator;
  readonly submit: Locator;
  readonly error: Locator;

  constructor(page: Page) {
    this.page = page;
    this.email = page.getByRole('textbox', { name: 'Email' });
    this.password = page.getByLabel('Password');
    this.submit = page.getByRole('button', { name: 'Sign in' });
    this.error = page.getByRole('alert');
  }

  async goto() { await this.page.goto('/login'); }

  async login(email: string, password: string) {
    await this.email.fill(email);
    await this.password.fill(password);
    await this.submit.click();
  }

  async expectError(message: string) {
    await expect(this.error).toHaveText(message);
  }
}

See our Playwright installation guide for full project setup.

3. Selenium POM in Java

public class LoginPage {
  private final WebDriver driver;
  @FindBy(id = "email")    private WebElement email;
  @FindBy(id = "password") private WebElement password;
  @FindBy(id = "submit")   private WebElement submit;

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

  public void login(String u, String p) {
    email.sendKeys(u);
    password.sendKeys(p);
    submit.click();
  }
}

Deep dive: Selenium interview questions.

4. Three POM anti-patterns

  1. God Page Objects — one class for a 40-section page. Split by component instead.
  2. Assertions inside the Page Object — hides intent, blocks reuse. Assert in the test.
  3. Sleeps and waits inside methods — mask timing bugs. Use auto-waiting locators.

5. When App Actions beats POM

For state setup (creating a user, seeding a cart), calling your API is 10x faster and more reliable than driving the UI. Reserve POM for what UI tests must verify — the UI itself. See Cypress's App Actions article for the canonical framing.

6. Migrating a 200-test suite

Sprint 1: convert your 5 highest-churn pages. Sprint 2: convert the next 15. Sprint 3: enforce with a lint rule that fails PRs importing raw selectors outside pages/. Track locator-change PRs per sprint — a healthy POM cuts them by 60%+ within a quarter. Pair with the test automation complete guide.

Frequently asked questions

1.Is POM still recommended in 2026?
Yes for UI-heavy suites over 100 tests. For small suites, plain helpers are simpler.
2.Should Page Objects hold assertions?
Only universal ones (page loaded, no console errors). Business assertions live in tests.
3.POM vs Screenplay Pattern?
Screenplay separates actor, task, and question — better for very large orgs, overkill for most teams.
4.Do I need POM in Cypress or Playwright with fixtures?
Fixtures reduce the need but don't replace it. Use both: fixtures for setup, POM for interactions.
Keep going

Practice these questions

Rehearse Selenium and Playwright automation questions covering framework design, waits, locators and CI/CD.

Found this useful?
Share:XLinkedInWhatsApp

Was this article helpful?

Keep building your QA edge

Continue reading

Topic mapConcepts · Tools · People · Standards

Related concepts, tools & standards around Automation Testing

A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Automation Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.

Core testing concepts
Test PyramidShift-Left TestingBehavior-Driven DevelopmentTest-Driven DevelopmentPage Object ModelContract TestingExploratory TestingRisk-Based TestingEquivalence PartitioningBoundary Value Analysis
Programming languages
JavaPythonJavaScriptTypeScriptC#SQL
Certifications worth knowing
ISTQB Foundation LevelISTQB Advanced — Test AnalystISTQB Agile TesterCertified Selenium ProfessionalAWS Certified DevOps EngineerCertified ScrumMaster (CSM)
Companies hiring for this skill
GoogleMicrosoftAmazonMetaNetflixAtlassianThoughtWorksInfosysTCSWipro

Discussion

Ask a question, share your experience, or correct us. Be kind — real people are reading.

Join the QA Community

Connect with fellow testers, share job leads, and get career advice.

Premium QA Resources

Stop Reinventing the Wheel. Upgrade Your QA Arsenal.

Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.

  • Ready-to-use testing strategy templates
  • Advanced API & UI automation guides
  • ⏱️ Save 10+ hours a week on test planning
4.9/5 rating
Explore All Products

⭐⭐⭐⭐⭐ Trusted by 1,000+ Software Test Pilots • Instant Access