Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

selector-drift-recovery

FreeRuns bundled scriptsNot checked

Bulk-regenerate broken test selectors after a UI refactor or redesign. Detects drift between old and new DOM with an aria-snapshot diff, maps old locators to…

petrkindlmannby petrkindlmann★ 317 GitHub stars

About this skill

A redesign shipped and 23 tests now fail with `TimeoutError: locator.* exceeded`. Establish whether the cause is locator drift or an application regression before changing tests. This skill closes that maintenance loop: it diffs the old DOM against the new one, regenerates the broken selectors role-first against the new build, validates the whole suite, and ships the diff as one reviewable PR with a confidence score and screenshot per change. The trigger is an event (a refactor merged), not a flake. The output is a PR a human signs off on — not a silent runtime auto-heal.

This is the bulk, offline, batch counterpart to test-reliability. They share the multi-attribute locator + confidence scoring primitives but run in opposite directions: test-reliability heals one selector at runtime behind a guarded threshold; selector-drift-recovery regenerates N selectors offline against the new DOM and bundles them into a PR. If you are doing the second workflow inside test-reliability, switch here.

Quick Route

Situation Go to
One broken test, not a refactor Stop — use test-reliability instead
200+ broken selectors across many files Split by area first (one PR per page/dir), then Phase 1
Refactor changed flows/semantics, not just structure Stop — rewrite from specs with playwright-automation
Framework switch (Selenium → Playwright) Stop — use test-migration, not drift recovery
No old-DOM reference exists anywhere Capture one (Phase 1) or scope down — without it this is "rewrite tests"
Have old + new DOM, ready to map Phase 1 → 6 below

Discovery Questions

Check .agents/qa-project-context.md first — if it exists, use it and skip anything answered there. It identifies your E2E framework, selector strategy, and known fragile areas. Then:

  1. What triggered the drift? A planned refactor (Storybook can show the new DOM before merge), a shipped redesign (new DOM is in main), a dependency upgrade, or a Tailwind/CSS migration? The trigger decides whether you run pre-emptively or react to CI failures.
  2. What is the blast radius? A single component, a page, or the whole app? Single component: scope recovery to the test files that touch it. Global: budget half a day to a day, and decide which tests should be rewritten rather than re-selected.
  3. What is your current selector strategy? If selectors are mostly data-testid and the refactor preserved testids, recovery is trivial. If they are CSS-class or XPath based, expect 30–60% to need a new strategy, not just a new locator.
  4. Is there a passing baseline? You need the old DOM somewhere: a previous CI trace artifact, a deployed staging build, a Storybook story, or git history of the components. No old-DOM reference means this degrades to "rewrite tests."
  5. Are the broken locators inline or wrapped in a Page Object? The JSON reporter's error.location points at the failing line. For inline locators that is the locator itself; for POM-wrapped locators it points at the POM helper, not the test. Know this before you trust the auto-extracted line numbers (see Failure Modes).
  6. Who reviews the resulting PR? Confidence-scored updates need a human signoff. Decide upfront whether the PR goes to the test author, the engineer who did the refactor, or the QA lead.

Core Principles

  1. Recovery is event-driven, not failure-driven. Run this when a refactor is planned or just shipped, not when one test goes flaky. One broken test → test-reliability. Ten or more from the same event → this skill.

  2. Old DOM, new DOM, mapped pair. The whole skill rests on a snapshot before the refactor and one after. Everything else is bookkeeping around that pair. Capture both as aria snapshots (await page.locator('body').ariaSnapshot()), not raw HTML — a role-tree diff is exactly the signal role-first recovery needs and ignores the cosmetic churn (class renames, wrapper divs) that a raw-HTML diff drowns in. If you cannot produce both snapshots, fix that first. The aria diff reports role and name drift only. A redesign that renames classes, ids and data-* hooks but keeps every role and name shows an empty aria diff while the whole suite fails. When the diff is empty and the tests are red, also diff a tag/id/class/data-*/aria-* outline of the markup (recovery-scripts §1); that is where a hook-only mapping comes from.

  3. Role-first replacement, every time. Even when the old test used CSS, the regenerated selector should prefer getByRole + accessible name, then getByLabel for form fields, then getByTestId when the refactor added one. The recovery PR is your chance to ratchet the average selector stability score up (0–5 rubric below, shared with test-reliability).

  4. Disambiguate by region scoping, not layout selectors. When role+name is ambiguous (two "Submit" buttons), narrow with `getByRole('region', { name }).

Full SKILL.md on GitHub

Install selector-drift-recovery in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

references/recovery-scripts.mdreferences/score-candidates.mjs

FAQ

What does the selector-drift-recovery skill do?

Bulk-regenerate broken test selectors after a UI refactor or redesign. Detects drift between old and new DOM with an aria-snapshot diff, maps old locators to new equivalents using role-first + region scoping, validates against the new build, and produces a single PR with grouped per-file selector updates and per-change evidence. Assumes Playwright >= 1.50 (trace viewer DOM-snapshot panel, getByRole filtering, ariaSnapshot). Use when: "UI refactor broke tests," "redesign broke tests," "bulk update selectors," "regenerate selectors after refactor," "selector drift," "fix N broken tests after redesign." Not for: healing one flaky test at runtime — use test-reliability. Not for: writing a new test suite from scratch — use playwright-automation. Not for: re-recording tests after a framework switch (Selenium to Playwright) — use test-migration. Related: test-reliability, playwright-automation, test-migration, ci-cd-integration, visual-testing.

How do I install the selector-drift-recovery skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the selector-drift-recovery skill run scripts?

Yes, this skill bundles executable scripts. Review the source before installing.

Related skills

Compare selector-drift-recovery with