World’s largest virtual agentic engineering & quality conference
Learn how playwright self healing tests work: auto heal detects broken selectors, fixes tests automatically, and keeps automation pipelines stable.

Salman Khan
Author
Srinivasan Sekar
Reviewer
Published on: November 29, 2025
Last Updated on: August 11, 2026
When you run Playwright tests, changes to element attributes, DOM structure, or selectors can cause tests to fail. However, implementing auto heal in Playwright testing can automatically identify broken locators and update them at runtime. This allows tests to continue executing without interruption, reducing false negatives, minimizing test maintenance, and ensuring that your test suite accurately reflects the functionality of your web application, even if its UI changes.
Overview
To implement self-healing tests, use Playwright semantic locators to maintain locator stability locally, or enable the cloud-based autoHeal capability on TestMu AI to automatically detect, resolve, and update broken selectors during remote test execution across different browsers and operating systems.
How Auto Heal Works in Playwright
How to Use Auto Heal in Playwright
Auto heal in Playwright testing refers to techniques that allow automated tests to recover from locator failures caused by UI changes. When a test script cannot find an element using its original selector, auto healing strategies attempt alternative ways to locate the element, such as using role-based locators, dynamic selectors, or retry logic.
Playwright does not include a fully built-in auto healing engine. However, you can use features like role-based Playwright locators, retry mechanisms, and dynamic selectors, which help create more reliable and maintainable tests. Per the official Playwright documentation, these locators resolve against the accessibility tree rather than raw DOM structure, which is why they survive most class or ID renames without any healing logic at all.
Playwright's official documentation describes it as an end-to-end test framework that bundles a test runner, assertions, isolation, and parallelization, and runs the same test across Chromium, WebKit, and Firefox. That shared framework is what lets the locator and retry strategies below work identically across every engine, without browser-specific healing logic.
Playwright enables resilient testing by combining strategies that make test execution more robust than traditional approaches. While it does not include a fully automatic auto healing engine, its features allow tests to adapt to minor UI changes and reduce ongoing maintenance.
Note: Run Playwright tests with auto healing across 3,000+ real browser and OS combinations. Try TestMu AI Now!
Let's look at Playwright auto heal mechanism to enhance test resilience, leveraging smart locators that adapt to UI changes automatically during execution.
Install Playwright using the command below:
npm init playwright@latestAfter Playwright installation, you'll have a fully configured project with:
Let's test a user registration flow on the TestMu AI eCommerce Playground website.
Test Scenario:
Implementation:
Here is the register.spec.js file optimized with resilience in mind:
import { test, expect } from '@playwright/test';
function generateEmail() {
const timestamp = Date.now();
return `user${timestamp}@mail.com`;
}
test('Create new user account with resilient locators', async ({ page }) => {
await page.goto('https://ecommerce-playground.lambdatest.io/index.php?route=account/register');
await page.getByLabel('First Name').fill('Maria');
await page.getByLabel('Last Name').fill('Costa');
await page.getByLabel('E-Mail').fill(generateEmail());
await page.getByLabel('Telephone').fill('+351123456789');
await page.getByLabel('Password', { exact: true }).fill('987654321');
await page.getByLabel('Password Confirm', { exact: true }).fill('987654321');
await page.getByText('Yes').click(); // Newsletter opt-in
await page.getByText('I have read and agree').click(); // Privacy Policy
await page.getByRole('button', { name: 'Continue' }).click();
await expect(page).toHaveTitle('Your Account Has Been Created!');
});
test('Create new user account with strategies for handling dynamic components', async ({ page }) => {
await page.goto('https://ecommerce-playground.lambdatest.io/index.php?route=account/register');
await expect(page.getByRole('heading', { level: 1 })).toHaveText('Register Account');
await page.getByLabel('First Name').fill('Maria');
await page.getByLabel('Last Name').fill('Costa');
await page.getByLabel('E-Mail').fill(generateEmail());
await page.getByLabel('Telephone').fill('+351123456789');
await page.getByLabel('Password', { exact: true }).waitFor({ state: 'visible' });
await page.getByLabel('Password', { exact: true }).fill('987654321');
await page.getByLabel('Password Confirm', { exact: true }).fill('987654321');
await page.getByText('Yes').click(); // Newsletter opt-in
await page.getByText('I have read and agree').click(); // Privacy Policy
await page.getByRole('button', { name: 'Continue' }).click();
await page.waitForURL(/.*account/success/);
await expect(page).toHaveTitle('Your Account Has Been Created!');
});
Why Is This Implementation "Auto Healing Ready":
Let's break down why the above test script is more resilient than one using static selectors:
Code Walkthrough:
Test Execution:
To run the above spec file, execute the following command:
npx playwright test tests/register.spec.js
Cloud testing platforms such as TestMu AI offer a Playwright automation cloud to run your tests at scale across different browsers and operating systems. This platform offers a Playwright autoHeal capability that stores metadata from successful runs and finds alternative selectors when failures occur.
When a test in the future runs into a missing selector, this autoHeal capability compares the current web page with the saved reference data. It then automatically looks for a matching element, and if one is found, the test keeps running without any interruption.
To get started, check out this guide to use Playwright auto healing on TestMu AI.
We will run the same test scenario using the autoHeal capability provided by TestMu AI.
The projects array below follows the standard structure documented in Playwright's test configuration reference, so the local Chromium, Firefox, and WebKit projects keep working exactly as before, with the TestMu AI cloud project added alongside them rather than replacing them.
To activate the Playwright autoHeal capability, all you need to do is configure a new project entry inside your playwright.config.js file. There's no need to change your test logic or add any dependencies, as the setup happens entirely through the configuration.
import { defineConfig, devices } from '@playwright/test';
const LT_USERNAME = process.env.LT_USERNAME;
const LT_ACCESS_KEY = process.env.LT_ACCESS_KEY;
const ltCapabilities = {
browserName: 'Chrome',
browserVersion: 'latest',
'LT:Options': {
platform: 'Windows 10',
build: 'Playwright Auto Heal Build',
name: 'Playwright Auto Heal Test',
autoHeal: true,
user: LT_USERNAME,
accessKey: LT_ACCESS_KEY,
},
};
const ltWsEndpoint = `wss://cdp.lambdatest.com/playwright?capabilities=${encodeURIComponent(JSON.stringify(ltCapabilities))}`;
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
{
name: 'TestMuAI-Chrome-AutoHeal',
use: {
connectOptions: {
wsEndpoint: ltWsEndpoint,
},
},
},
],
});Code Walkthrough:
Test Execution:
To run your tests using the Playwright autoHeal capability, simply execute the command below:
npx playwright test --project=TestMuAI-Chrome-AutoHeal
Pro-tip: You can also leverage Generative AI testing agents like TestMu AI KaneAI that enhance automation reliability with its GenAI-native auto heal feature.
Instead of failing immediately when locators break, the auto heal feature dynamically identifies alternative locators at runtime, leveraging the natural language prompts used to generate the test.
To get started, check out this documentation on using auto healing in TestMu AI KaneAI.
Playwright auto healing capabilities bring flexibility to UI automation, but it is essential to understand where they work and where they have limitations.
This can let tests pass while the actual user experience is broken. The risk is higher when relying on text- or role-based selectors, as healed interactions may hit visually similar but functionally different elements, giving the test suite a misleading sense of reliability.
Frequent healing attempts also increase execution time, especially in large test suites or pipelines, since retries and alternative locator resolutions add overhead that compounds at scale.
Auto‑healing can save significant effort in maintaining test suites in applications where the UI frequently changes. To benefit fully without introducing hidden risks, it must be used consciously.
Here are some best practices to balance robustness and correctness when enabling and relying on Playwright's auto‑heal capabilities:
Auto healing in Playwright helps maintain reliable tests despite frequent UI changes by automatically recovering from minor DOM or attribute modifications. It works through resilient locator strategies, automatic retries, and adaptive behavior, reducing the need for constant manual intervention.
Platforms like TestMu AI enhance this capability by dynamically finding alternative locators during cloud execution. While auto healing improves test stability, it is not a substitute for good test design, making monitoring and validations essential.
Combining auto healing with strategies for handling dynamic components and enforcing strong assertions allows you to build robust, maintainable, and adaptive test suites. For teams exploring AI-driven automation further, Playwright Agents offer autonomous test generation that pairs well with self-healing workflows.
Author
Salman is a Test Automation Evangelist and Community Contributor at TestMu AI, with over 6 years of hands-on experience in software testing and automation. He has completed his Master of Technology in Computer Science and Engineering, demonstrating strong technical expertise in software development, testing, AI agents and LLMs. He is certified in KaneAI, Automation Testing, Selenium, Cypress, Playwright, and Appium, with deep experience in CI/CD pipelines, cross-browser testing, AI in testing, and mobile automation. Salman works closely with engineering teams to convert complex testing concepts into actionable, developer-first content. Salman has authored 120+ technical tutorials, guides, and documentation on test automation, web development, and related domains, making him a strong voice in the QA and testing community.
Reviewer
Srinivasan Sekar is Director of Engineering at TestMu AI (formerly LambdaTest), where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.
Did you find this page helpful?
More Related Blogs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance