Expertise hub / AI-assisted testing
AI-assisted testing 9 min read

Self-healing tests: how AI repairs locators automatically

A designer renames a CSS class, and dozens of tests break. Not because of a bug, but because of an outdated locator.

As a result, teams typically lose 40 to 60% of their automation time on maintenance instead of expanding coverage.

Self-healing test automation tackles exactly that problem: when a locator fails, the system itself looks for the correct element via alternative attributes (text, ARIA labels, DOM position, visual similarity) and automatically suggests a new locator or temporarily adjusts the test, depending on the chosen strategy.

What it solves, and what it doesn't

// What self-healing typically catches
Renamed CSS class or IDrepaired automatically
Shifted element in the DOMrepaired automatically
Slow API response (timing)caught with retries
Genuine functional changetest correctly fails

That last one is the most important distinction. Good self-healing doesn't hide genuine regressions: it only solves the "noise" problem, cosmetic changes that say nothing about the quality of the application. Vendors who claim their tool "never fails again" deserve suspicion: a test that no longer detects anything is no longer a test.

Selector healing resolves around 28% of real test failures on average. Timing-related issues, often wrongly attributed to a "broken locator", are actually the largest category at 30%.

Where it concretely pays off

What it doesn't solve

Major redesigns

A completely renewed interface still requires human reassessment. Self-healing resolves incremental changes, not architectural overhauls.

Poor test architecture

Self-healing is not a replacement for stable, meaningful locators (data-testid, ARIA roles). It's a safety net, not a foundation.

We deploy self-healing as a complement to a well-structured suite, not a replacement for one, and always with a log of every automatic repair, so your team can review every change before it becomes final.

An example from practice

At a client with an Angular checkout flow, the frontend team renamed a CSS class during a routine restyling. No functional change, just a renamed class in the design system. Result: 34 tests failed that same night, spread across five test suites, and the team started the morning with "red" instead of new work.

// Before: locator relies on a styling class await page.locator('.btn-primary-v2').click(); // After the restyle: '.btn-primary-v2' no longer exists // → "element not found", test fails, no functional regression // Self-healing walks a fallback hierarchy: // 1. data-testid, if present // 2. ARIA role + visible text // 3. DOM position relative to the last successful run // 4. visual similarity (last resort) // Suggested, more stable locator: await page.getByRole('button', { name: 'Confirm order' }).click();

The system automatically proposed the new locator, but the test kept running with the old one until an engineer explicitly approved the proposal. That's the difference between self-healing as a safety net and self-healing as a black box: the suite stayed green, but nobody lost control over what exactly changed.

The four most common breaking points, and the fix

Not every "broken" test has the same root cause. Across the suites we maintain for clients, the same four patterns keep recurring, each needing a different fix.

// Cause → practical fix
CSS class or ID renamed by the frontend teamenforce a data-testid convention
Element moved after a DOM restructureanchor on a stable parent + text
A/B test shows two alternating variantsvariant-aware locator strategy
Component-library upgrade changes markupARIA role instead of CSS selector

A/B testing breaks tests "at random"

When marketing runs an experiment, half the test runs see variant A and the other half variant B. That looks like flakiness, but it's a locator problem: the test needs to recognize both variants through a shared attribute (role, text, data attribute), not through the specific markup of one variant. Self-healing can compensate for this, but the underlying design is better fixed at the source.

A library upgrade breaks hundreds of tests at once

When a team moves to a new major version of a component library, the entire underlying DOM structure often changes in one go. Selector-healing works best here when tests already rely on ARIA roles and visible text: those tend to survive a library upgrade unscathed, while deeply nested CSS selectors have to be rewritten one by one.

How we roll out self-healing at clients

// Less maintenance, more coverage

Curious how much maintenance time self-healing could save you?

We review your current suite and show concretely where automatic repair makes the difference.

Book a call
// Read also