agentleFS
anhtesteranhtester/codex-testing-kit/.agents/skills/locator-healer-agent/SKILL.md

locator-healer-agent

Skill28 starsChanged 4 months agoMITView on GitHub

Skill tự động phát hiện và sửa chữa locators bị hỏng khi automation tests fail do thay đổi DOM.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 14
  2. Distinctive:

    After a frontend deployment that modifies DOM structure

    line 18
  3. Distinctive:

    When a locator fails:

    line 24
  4. Distinctive:

    Read error log to identify which locator failed

    line 48
  5. Distinctive:

    Verify the new locator matches exactly one element

    line 67
  6. Distinctive:

    Verify the element is the correct one (text, position, behavior)

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Locator Healer Agent

Purpose: Automatically repair broken locators when automation tests fail.


When to Use

Use this skill when:

  • A test fails with "element not found" or "element detached" errors
  • UI has changed and existing locators no longer work
  • After a frontend deployment that modifies DOM structure

Responsibilities

When a locator fails:

  1. Inspect current DOM or UI hierarchy
  2. Compare old locator with current page structure
  3. Identify updated attributes
  4. Generate a replacement locator
  5. Re-run test to verify the fix

Detection Strategy

Locator is considered broken when:

  • Element not found (NoSuchElementException / TimeoutError)
  • Element detached from DOM
  • Selector matches zero elements
  • Selector matches wrong element (different text/position)

Healing Workflow

Step 1: Analyze the Error

  • Read error log to identify which locator failed
  • Identify the Page Object file and line number

Step 2: Inspect Current DOM

  • Open the page using MCP tools
  • Navigate to the same state as the failing test
  • Inspect the target area in DOM

Step 3: Find Alternative Locator

Try the following in priority order:

  1. Accessibility attributes (aria-label, role)
  2. data-testid / data-test
  3. id (if stable, not auto-generated)
  4. Semantic locator (Playwright getByRole, getByLabel)
  5. css selector (stable attributes)
  6. xpath (relative, not positional)

Step 4: Validate & Replace

  • Verify the new locator matches exactly one element
  • Verify the element is the correct one (text, position, behavior)
  • Replace the broken locator in the Page Object class
  • Re-run the test

Difference from Smart Locator Agent

AspectLocator HealerSmart Locator
TriggerTest failure (reactive)New element (proactive)
InputBroken locator + error logHTML/DOM element
GoalFix existing locatorGenerate new locator
WorkflowError → Inspect → Replace → VerifyInspect → Generate → Validate

Verification

After healing:

  • Locator must match exactly one element
  • Element is the correct target (verify text/attributes)
  • Test must pass successfully
  • Locator is stable across page reloads

Rules References

  • .agents/rules/locator_strategy.md — Master locator priority map
  • .agents/rules/automation_rules.md — General automation best practices

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.