Skip to content

QA-PW-146 — CSS/XPath string selector instead of a normalized locator ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-PW-146.

FieldValue
Severitywarning
Confidencemedium
Tierquarantine
Measured FP rate12% (n=17)
Evidence levelE1
QA impactTest hygiene debt (HYGIENE)
False-positive risk (author estimate)medium
Autofix availableno
Languagestypescript, javascript
Frameworksplaywright
Detection strategyLEXICAL (string-selector shapes (css=/xpath= engines, bare id/class/attr CSS, nth-child) inside .locator()/waitForSelector()/page.$ APIs, on the RAW text view (the selector text lives inside string literals, which the code-only view blanks))
Introduced inv0.6.0

Why this fails in production ​

String CSS/XPath selectors couple the test to markup the user never sees — they break on any refactor and can silently select the wrong element after a redesign.

What gets flagged (real detector output) ​

CSS/XPath string selector where a normalized locator is expected.

Example from this rule's own must-fire fixture: tests/fixtures/QA-PW-146/must-fire/selectors.spec.ts

The fix ​

Normalize to Playwright's user-facing getters: getByRole('button', { name: '…' }), getByLabel('…'), getByTestId('…'), or getByText('…') — they survive markup refactors and match what a user actually perceives.

Confirmed NOT to fire on the corresponding clean pattern ​

Verified against tests/fixtures/QA-PW-146/must-not-fire/selectors.spec.ts — a legitimate, similar-looking pattern this rule correctly leaves alone.

Corpus-measured false-positive risk ​

Real occurrence counts from npm run corpus:audit against actively-maintained OSS repos — reproduce yourself, don't just trust this table (see the false-positive audit):

RepoOccurrences
github-docs76
grafana-grafana253
hashicorp-vault32
Humanizr-Humanizer18
keycloak-keycloak67
negative-fixtures2
nextauthjs-next-auth1
playwright-community-eslint-plugin-playwright235
positive-fixtures15
puppeteer-puppeteer228
sveltejs-kit409
vercel-next-js158
vitejs-vite117
vitest-dev-vitest23
withastro-astro498

Released under the MIT License.