AI + Testing

Self-healing tests: how AI agents fix broken locators (and where they can't)

Audit any mature UI automation suite and you'll find the same cost centre: test maintenance, and within it, one dominant failure type — the element is still on the page, the feature still works, but the locator no longer matches. A developer renamed a class, restructured a component, or changed "Buy now" to "Buy Now". The product didn't break; your test did. Teams routinely burn a day per sprint on exactly this, and it's the main reason automation efforts quietly die.

"Self-healing tests" is the promise that this entire category of maintenance disappears. In 2026, with LLM-based agents, the promise is finally mostly real — but you need to understand what the agent actually does, because "mostly" is doing some work in that sentence.

The healing loop, step by step

Strip away vendor branding and every self-healing system runs the same loop:

  1. Detect the right kind of failure. A locator that finds nothing (or times out on an element that clearly should exist) is a healing candidate. An assertion failure is not — that might be a genuine bug, and "healing" it would be hiding it.
  2. Re-read the live page. The agent captures the current DOM or accessibility tree — the page as it is now, not as it was when the test was written.
  3. Match intent to the new structure. This is where LLMs changed the game. Older self-healing tools compared attribute similarity — id, class, position — and picked the closest node. An LLM matches meaning: it knows the test wanted the checkout button, reads the new page, and recognises that Proceed to payment now plays that role even though every attribute changed.
  4. Propose, verify, re-run. The agent suggests a replacement locator, the step is retried, and the test continues. Good setups log the heal; the best ones open a pull request updating the spec, so a human approves the change and the repair becomes permanent instead of silently re-applied every night.

A concrete example

A spec written in March:

await page.getByRole('button', { name: 'Buy now' }).click();

In June, a redesign ships: the button is now inside a new component and reads "Proceed to payment". The locator times out. The agent re-reads the accessibility tree, finds one button in the checkout region with purchase semantics, and proposes:

await page.getByRole('button', { name: 'Proceed to payment' }).click();

The test re-runs and passes. Elapsed time: seconds, not a Jira ticket. Multiply by the forty specs that touched that button and you understand the excitement.

Where self-healing fails — and the honest caveats

  • It can heal a test into lying. The most dangerous failure mode: the button was genuinely removed by mistake, and an over-eager agent "heals" the test to click something else — turning a real bug into a green build. This is why assertion failures must never be healable, and why heals need human review.
  • Ambiguity breaks it. Two similar buttons ("Save" and "Save as draft") after a redesign is a coin flip. Agents are confident coin-flippers.
  • It can't heal missing intent. If the flow itself changed — checkout is now three steps instead of one — locator repair can't restructure the journey. That's re-authoring, and it needs either a human or a much more capable (and supervised) agent session.
  • Cost and nondeterminism. Every heal is an LLM call inside your pipeline. Budget for it, cache what you can, and pin your prompts — a healing step that behaves differently every Tuesday is its own kind of flaky.

How to adopt it without getting burned

  • Write healable locators first. Ironically, self-healing works best on suites that need it least: role-based, user-facing locators give the agent clear intent to work with. div:nth-child(4) gives it nothing.
  • Heal in review mode before autopilot. Start with the agent proposing fixes as pull requests. Once you trust its judgment on your app, allow auto-heal for locator-not-found cases only.
  • Track the heal log like a metric. Frequent heals in one area are a signal — either the dev team needs stable test ids there, or your locator strategy needs work. Healing is a painkiller; the log tells you where the disease is.

Self-healing doesn't remove the engineer from test maintenance. It changes the job from typing repairs to reviewing them — which is faster, but only safe if you understand what a correct repair looks like.

The skill behind the buzzword

Every automation job posting now mentions AI. The candidates who stand out aren't the ones who say "I used a self-healing tool" — they're the ones who can explain the loop above, name its failure modes, and describe when they'd refuse to let the agent heal. That depth is teachable, and it's exactly what separates a tool user from an engineer.

We build a self-healing workflow from scratch in my course — including the review gates that keep it honest. Live, hands-on, 45 days.

See the 45-day plan →