lecture 7 of 170 completed

Locator strategy and making the app testable

At scale, locators are a policy rather than a skill. And the biggest wins come from changing the application, not the tests.

What you'll learn

  • How to turn a locator preference into an enforced policy
  • How to get developers to make the app testable
  • Why strict mode failures are worth reading, not silencing

Four hundred brittle selectors, no test IDs, and a redesign next quarter. This is one of the most common situations a senior engineer inherits, and the fix is only half technical.

The technical half: a locator hierarchy, written down.

Playwright's own guidance is user-facing locators first, and at scale that needs to become a policy rather than a preference:

1. Role and accessible name. getByRole('button', { name: 'Save contact' }). Best default. Stable, readable, and it fails when a screen reader user would also struggle, which means your suite checks accessibility for free.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →