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.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →