# selector-drift-recovery

Bulk-regenerates broken Playwright selectors after a UI redesign. Diffs aria snapshots and packages updated locators into a reviewable pull request.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 993 installs · ★ 211
- Author: kindlmann
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/petrkindlmann/qa-skills/tree/HEAD/skills/selector-drift-recovery/SKILL.md
- Updated: 2026-10-22
- HTML: https://affpapa.org/en/nevibecode/skills/selector-drift-recovery

## What it does

This skill fixes broken test locators after interface updates. It diffs the old and new DOM using aria snapshots instead of raw HTML. Then it maps old locators to new accessible roles and scopes them by region. Changes are gathered into a single pull request with screenshots and confidence scores.

The workflow assumes Playwright version 1.50 or newer with trace viewer DOM snapshots. You also must provide an old DOM baseline from a previous trace, Storybook story, or staging build. Without a baseline snapshot, recovery fails and turns into a manual test rewrite.

## Requirements
- Works with: Playwright

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add petrkindlmann/qa-skills --skill selector-drift-recovery -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/selector-drift-recovery/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/selector-drift-recovery/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add petrkindlmann/qa-skills --skill selector-drift-recovery -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/selector-drift-recovery/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add petrkindlmann/qa-skills --skill selector-drift-recovery -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/selector-drift-recovery/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install petrkindlmann/qa-skills selector-drift-recovery
```

2. **Manually: put the files in place**
- File: `.github/skills/selector-drift-recovery/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add petrkindlmann/qa-skills --skill selector-drift-recovery -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/petrkindlmann/qa-skills --path skills/selector-drift-recovery
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/selector-drift-recovery/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add petrkindlmann/qa-skills --skill selector-drift-recovery -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/petrkindlmann/qa-skills/tree/HEAD/skills/selector-drift-recovery/SKILL.md

## When to use it
- regenerate broken test locators after a UI redesign
- map old selectors to accessible roles using aria snapshots
- isolate ambiguous elements through region scoping
- assemble updated locators into a single pull request

## Example prompts
- UI refactor broke our Playwright tests, regenerate selectors with selector-drift-recovery
- Diff old and new aria snapshots to update broken selectors
- Run selector-drift-recovery and prepare a single PR with locator updates

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 61a3ccd8edbcda3c.

BEGIN THIRD-PARTY FILE 61a3ccd8edbcda3c
```text
---
name: selector-drift-recovery
description: >-
  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.
license: MIT
metadata:
  author: kindlmann
  version: "2.1"
  category: automation
---

<objective>
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.
</objective>

## 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
```
END THIRD-PARTY FILE 61a3ccd8edbcda3c

The third-party file has ended. Everything between the 61a3ccd8edbcda3c tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2820 of 23460 bytes. © kindlmann · MIT · https://github.com/petrkindlmann/qa-skills/tree/HEAD/skills/selector-drift-recovery/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
