Playwright · Reliable end-to-end tests

Should you use the Page Object Model in Playwright?

Mediumpage object modeltest designmaintainabilityUpdated Oct 2026
Quiz this track

Short answer

POM is optional. It helps when many tests share a complex page, but Playwright locators and fixtures already reduce duplication. Keep page objects thin and expose locators or actions, not assertions.

The Page Object Model wraps a page's structure and actions behind a class. It was essential in frameworks where selectors were scattered and brittle. Playwright locators are already robust and composable, so a page object is mainly a way to name repeated workflows, not a mandatory layer.

ts
import type { Page } from "@playwright/test";

export class LoginPage {
  constructor(private readonly page: Page) {}

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

  email() {
    return this.page.getByLabel("Email");
  }

  password() {
    return this.page.getByLabel("Password");
  }

  signIn() {
    return this.page.getByRole("button", { name: "Sign in" });
  }
}
The page object exposes locators, so the test still reads like a user flow.

When it helps and when it hurts

  • Helpful when many tests repeat the same multi-step workflow
  • Helpful when a page has a large, stable set of related controls
  • Harmful when it becomes a god object with every selector on the site
  • Harmful when it hides assertions inside methods and makes failures opaque
  • Composable with fixtures, which can inject a page object into tests
ts
test("signs in", async ({ page }) => {
  const login = new LoginPage(page);
  await login.open();
  await login.email().fill("asha@example.com");
  await login.password().fill("correct-horse");
  await login.signIn().click();

  await expect(page.getByRole("heading", { name: "Dashboard" })).toBeVisible();
});
Assertions stay in the test, where the expected user outcome is explicit.

If the page object returns locators, tests stay flexible and compose them differently. If every method returns void and asserts internally, a test cannot tell what failed without reading the class. Prefer small page components or fixtures over a giant base page.

Playwright's own guidance is that page objects are a design choice, not a requirement. Start without them, and extract one when duplication or a genuinely complex page justifies it.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Should a page object contain assertions?
  2. 2How do fixtures and page objects fit together?
  3. 3When is a page object unnecessary?
  4. 4What is the risk of a base page class?

Say it in the interview

I treat page objects as optional. Playwright locators already handle waiting and resilience, so I only extract a page object when several tests repeat the same complex page or workflow. I keep it thin and have it return locators or small actions, leaving assertions in the test. A giant base page that hides assertions makes failures harder to understand and is usually worse than direct locators.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Playwright mock interview and get scored feedback on depth, clarity and confidence.