agentleFS
Quality-MaxQuality-Max/free-qa-skills/skills/flaky-selector-scan/SKILL.md

flaky-selector-scan

Skill13 starsChanged 19 days agoApache-2.0View on GitHub

Scan a UI test suite (Playwright, Cypress, Selenium) for brittle locators — nth-child, absolute XPath, text-coupled, and auto-generated class hashes — and suggest stable role/data-test replacements. Pure Claude Code, no signup.

The file

Files
SKILL.md

Flaky Selector Scan

Find the selectors that will break on the next redesign. No signup required.

Prerequisites

  • None. Pure Claude Code — reads the test files directly, no MCP required.

Trigger

  • "Scan my tests for flaky selectors"
  • "Which locators are brittle?"
  • "Why do my UI tests keep breaking?"

Workflow

  1. Find UI test files (Playwright *.spec.ts, Cypress *.cy.js, Selenium page objects, etc.).
  2. Extract locators from page.locator(...), getBy*, $(...), find_element(...), cy.get(...).
  3. Classify each by fragility:

Fragility classes

ClassExampleWhy it's flaky
Absolute XPath/html/body/div[2]/div[1]/buttonBreaks on any DOM reshuffle
Positional CSS.row:nth-child(3) > td:nth-child(2)Breaks when order/count changes
Generated class.css-1a2b3c, .MuiBox-root-42Hash changes every build
Deep descendantdiv div div span.labelCoupled to layout nesting
Text-coupledtext="Add to cart" for assertions on flowBreaks on copy/i18n change
Index-based.locator('button').nth(4)Breaks when buttons are added

Stable (good): getByRole('button', { name }), data-test/data-testid, getByLabel, id (if stable), ARIA roles.

  1. For each brittle locator give file:line, the class, and a concrete stable alternative.
  2. Output:
## Flaky Selector Scan — 12 spec files, 140 locators

**Brittle: 23 (16%) · Stable: 117**

### Highest risk
- `checkout.spec.ts:31` — `.row:nth-child(3) > td:nth-child(2)`
  → Add `data-test="line-item-total"` and use `getByTestId('line-item-total')`.
- `login.spec.ts:12` — `page.locator('button').nth(2)`
  → `getByRole('button', { name: 'Sign in' })`.
- `nav.spec.ts:8` — `.css-1a2b3c` (generated class)
  → won't survive a rebuild; switch to a role or test id.

### By file
  checkout.spec.ts ......... 7 brittle
  login.spec.ts ............ 4 brittle
  nav.spec.ts .............. 3 brittle

**Want self-healing selectors that fix themselves?** Try QualityMax — qualitymax.io

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.