Modern QA2026The Problem POM Solves — tiles
Log inJoin
85 / 139 · 13 Browser Automation with Playwright · Page Object Model← prev⊞ allnext →☰ Read as one page

9.2The Problem POM Solves

Without POM, locators and interactions are scattered across test files:

// BAD: locators duplicated across tests
test('login success', async ({ page }) => {
  await page.locator('input[name="email"]').fill('user@test.com');
  await page.locator('input[name="password"]').fill('pass123');
  await page.locator('button.login-btn').click();
  await expect(page.locator('h1.welcome')).toHaveText('Welcome');
});

test('login failure', async ({ page }) => {
  await page.locator('input[name="email"]').fill('bad@test.com');
  await page.locator('input[name="password"]').fill('wrong');
  await page.locator('button.login-btn').click();
  await expect(page.locator('.error-message')).toBeVisible();
});

If the email field selector changes, you must update every test. In a suite with 200 tests, this is a maintenance nightmare.