Skip to content

QA-PW-004 — Brittle selector instead of role-based locator ​

← Back to the rule catalog

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

FieldValue
Severitywarning
Confidencemedium
Tierquarantine
Measured FP rate43% (n=14)
Evidence levelE1
QA impactTest hygiene debt (HYGIENE)
False-positive risk (author estimate)medium
Autofix availableno
Languagestypescript, javascript
Frameworksplaywright
Detection strategyLEXICAL (regex pattern + inside-string oracle)
Introduced inv0.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):

RepoOccurrences
dubinc-dub2
grafana-grafana5
hashicorp-vault2
positive-fixtures8
vitejs-vite1

Released under the MIT License.