QA-PW-004 — Brittle selector instead of role-based locator
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-PW-004.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | medium |
| Tier | quarantine |
| Measured FP rate | 43% (n=14) |
| Evidence level | E1 |
| QA impact | Test hygiene debt (HYGIENE) |
| False-positive risk (author estimate) | medium |
| Autofix available | no |
| Languages | typescript, javascript |
| Frameworks | playwright |
| Detection strategy | LEXICAL (regex pattern + inside-string oracle) |
| Introduced in | v0.1.0 |
Why this fails in production
Structural selectors break on any DOM refactor and fail without telling you which behavior regressed.
What gets flagged (real detector output)
Brittle multi-class CSS selector: `locator(".btn.btn-primary.btn-lg")`.Example from this rule's own must-fire fixture: tests/fixtures/QA-PW-004/must-fire/brittle.spec.ts
The fix
Prefer role-based locators: getByRole(), getByText(), getByLabel().
Confirmed NOT to fire on the corresponding clean pattern
Verified against tests/fixtures/QA-PW-004/must-not-fire/clean.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):
| Repo | Occurrences |
|---|---|
| dubinc-dub | 2 |
| grafana-grafana | 5 |
| hashicorp-vault | 2 |
| positive-fixtures | 8 |
| vitejs-vite | 1 |