Self-healing tests: can AI repair a failed test by itself?
Updated:
Self-healing testing describes a feature that looks for a replacement element or suggests a new selector after the interface changes. It can reduce the time spent on routine maintenance. If it approves the change without review, however, it can redirect the test to the wrong behaviour and create a false sense of confidence.
What is the problem?
Test maintenance is a real cost. A suite that nobody repairs after application changes may gradually lose its value. Self-healing primarily addresses cases in which an element’s name or location changes while the expected behaviour remains the same.
The tool may not be able to determine the reason for the change reliably from the similarity of elements. A button may have been legitimately renamed, but it may also have disappeared because of a defect. Automatically accepting a replacement in the latter case may hide the very problem the test was supposed to highlight.
When it can help and when it is risky
It makes sense to assess a repair proposal for a small, understandable change where the element’s purpose has remained the same. A change to the user journey, business rule or result needs human assessment.
If an element’s identifier changes, a suggested replacement can save the time needed to find it. Self-healing may not distinguish an approved change from a form defect, however, so it is important to see both the difference and the reason for the change.
Illustrative risks with weak or incorrectly redirected assertions:
- The Submit button disappears because of a defect. Self-healing finds another button on the page as a replacement, such as Cancel, and redirects the test to it. If a proper order-creation assertion is missing, the test may pass without submitting the order.
- A field is renamed because the form logic has changed. The tool finds another field with a similar name, the test enters data into it and finishes green, even though it checked something entirely different.
- The result check is attached to an element that happens to exist on the page but means something else. The test is green but did not verify the original result.
Each of these cases can create false confidence: the test passes even though it has not checked its original objective. It is therefore important to distinguish an automatically suggested repair from an automatically approved repair.
How we address it
AI prepares maintenance proposals that we review before accepting.
When the interface changes and a test fails, AI can suggest a repair together with the difference between the original and the new element. A tester then decides whether this is an approved application change or a defect the test correctly detected. The change is accepted only after the expected result has been checked.
At the same time, we reduce the need for repairs by using stable selectors and, depending on the size of the project, a suitable layer of page or component objects. A change to one element can then be made in a shared location instead of in many tests.
Distinguish runtime recovery from a code change
The same label can cover different mechanisms:
| Mechanism | What to check |
|---|---|
| Replacement locator during execution | Which element was used, why it was selected and whether the replacement was stored for later runs. |
| Suggested test patch | The code diff, preservation of data and assertions, approval and the subsequent execution result. |
| Waiting or retrying | Whether the same condition remains and information about the original failure is preserved. |
Playwright describes automatic waiting and retrying assertions. These wait for a specified condition and do not, by themselves, approve a new meaning for the test. Separately, Playwright Test Agents include a healer, which may propose locator, wait and data changes. This is a workflow built around Playwright Test, rather than automatically the same feature in every Python project using pytest-playwright.
Establish what the particular tool changes and where it records the outcome. A high element-similarity score is not evidence that a click fulfils the original business intent. Approval in our process comes from comparison with the requirement.
Establish the cause before repairing the test
An element may be missing because its locator changed, but also because the user is not signed in, lacks permission, received incorrect data or the feature failed to load. Looking for another button does not resolve those underlying causes.
First, preserve the failing step, application version, account and data. Check which page and state the test actually reached. Compare expected behaviour with the approved product change. Only then decide whether the test, data, environment or product needs fixing.
If a scenario checks that a user must not see an element, replacement lookup may change the check’s meaning. Healenium explicitly documents disabling healing when checking an element’s absence. Verify whether your tool supports this and what the setting covers.
What should remain unchanged during repair
Define the permitted repair scope before the tool starts changing the test. When repairing element identification, preserve the same test data, expected result and essential assertions. Removing a step, changing the expected amount or switching to an account with greater privileges is more than a locator repair.
Illustrative scenario: a customer submits an order for two units of a product. A replacement locator may find a renamed button, but the test must still check the correct product, a quantity of two and the created order. If the new element only closes the form, a successful click has not met the requirement.
For writes, also consider the state after failure. The test may have created the order before confirmation was lost. Replaying the entire scenario belongs in a controlled test environment with agreed data setup and cleanup. An uncertain write result is not a reason for blind retries.
Include cases that must not be repaired in the pilot
Use one prepared set of test situations to compare repair proposals with expectations established beforehand:
| Situation | Expected decision |
|---|---|
| The test ID changed, while purpose and result remained the same | Assess the replacement locator and verify the original outcome. |
| The submit button disappeared because of a defect, leaving a cancel button | Preserve the failure and address the product defect. |
| The application saves one unit instead of the required two | Keep the expected quantity of two, rather than rewriting it to match the application. |
| It is unclear whether the order was already created | Establish the data state before starting another write. |
The assertion itself must detect the deliberately incorrect result, rather than merely a failure in account setup. Review proposals against the whole scenario as well. A repaired locator that targets the wrong order is not acceptable just because the element exists.
Report repairs while preserving coverage
Keep the original failure, proposal, decision rationale, approved diff and verification result. For runtime recovery, retain the actual replacement as well. Otherwise, the next person may see only a green report without knowing that execution deviated from the original test.
Playwright Test Agents documentation also describes skipping a test if the healer believes the feature is broken. A skip is not a successful repair. It must remain visible with its reason, owner and coverage impact. This outcome of a particular workflow must not be treated as a rule for every tool.
Assess maintenance time saved alongside review time, rejected proposals and cases where a repair would conceal a defect. Repeated repairs to the same element are a reason to review the locator and test design. After accepting a change, also check other scenarios using the shared page object. A successful pilot needs evidence that checks retain their meaning, rather than simply producing more green runs.
What you gain
- A faster repair proposal without having to find every selector from the beginning.
- An audit trail and deliberate approval of changes to tests.
- A lower risk that an automatic repair will hide an application defect.
Next step
For each self-healing change, start by recording the original selector, the proposed change and the result of the review. If you would like to assess where self-healing is safe in your suite, use a no-obligation consultation.