no-locators-in-tests
Locators live in page objects, not in tests
| Property | Value |
|---|---|
| Tier | MUST_NOT |
| Severity | error |
| Enforcement | ESLint (AST) |
| Autofix | no |
| Skill | stage-map |
| Applies to | tests/**/*.ts |
| Exempt | tests/**/*.setup.ts |
| Since | 1.0.0 |
Why
A locator defined inline in a spec is invisible to every other spec. When the markup changes, the edit has to be found by grep across the suite rather than made once in the page object. Tests read as intent; page objects hold the addressing.
What to do instead
Move this locator into the page object for the screen, expose it as a getter, and use it through the fixture: await loginPage.submitButton.click(). A spec file should name intent, not addressing. See the page-objects skill for the three-section locator layout.
Examples
// ✗ no-locators-in-tests
await page.getByRole('button', { name: 'Log in' }).click();
// ✓
await loginPage.logInButton.click();