Glossary · AI in testing
Self-healing locator
Also called: self-healing locators, self-healing tests, self-healing test automation, auto-healing locators
Definition
A locator that, when it no longer matches, has the test tool pick a likely replacement element from stored attributes or a model, and lets the test continue.
A self-healing locator is a UI test locator backed by a recovery mechanism. When the primary locator fails to find an element, for example because an id changed, the tool searches the page for the element that best matches what it knew about the original (tag, text, attributes, position, neighbours), uses it, and usually records the “heal” so someone can update the test. The aim is fewer failures caused by harmless markup changes.
How it works in practice
Most implementations follow the same pattern:
- On passing runs, store a fingerprint of each element the test touches.
- When a locator fails, score candidate elements on the page against that fingerprint.
- If the best candidate scores above a threshold, use it and log the substitution; otherwise fail normally.
Attribute-similarity healing of this kind is established: commercial tools offer it, and Healenium is an open-source option for Selenium. LLM-based healing, where a model reads the page or accessibility tree and proposes a new locator or a patched test, is newer. Playwright’s test agents, introduced in 1.56, include a healer that suggests fixes for failing tests; treat these as assistants that propose changes for review, not as an autopilot.
The real risk: healing a genuine bug
A heal assumes the change was cosmetic. Sometimes it was not:
- The “Submit” button was removed by mistake, and the healer clicks “Save draft” instead.
- A field was relabelled from “Email” to “Username”, a real requirement change the test should have flagged.
- Two similar rows exist and the healer picks the wrong one, so the test passes against the wrong data.
In each case a test that should fail goes green. Rules that keep healing honest:
- Report every heal, and fail the run (or at least flag it) in the release gate.
- Turn heals into code changes. Accept or reject the suggested locator in review; do not let the tool silently keep using it.
- Assert outcomes, not just interactions, so clicking the wrong element still fails on the next assertion.
Fix the locators first
Much of the brittleness self-healing targets comes from fragile selectors: long XPath chains, generated class names, index-based paths. User-facing locators such as Playwright’s getByRole('button', { name: 'Submit' }) or stable data-testid attributes remove most of that need without any guessing.