Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
Learn how auto heal in Playwright detects broken selectors, fix tests automatically, and helps maintain stable, reliable, self healing automation pipelines.
Published on: October 12, 2025
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.
Auto heal in Playwright helps maintain test stability by detecting when elements change and updating failing locators automatically. This reduces manual fixes and ensures tests continue to run reliably even when page structures evolve.
How Auto Heal Works in Playwright?
Playwright’s auto heal feature intelligently identifies broken locators, finds valid alternatives, and updates them dynamically, keeping tests functional despite minor UI changes.
How to Use Auto Heal in Playwright?
Cloud testing platforms like LambdaTest offers an auto heal feature for Playwright, which automatically detects and updates failing locators during test execution, helping maintain stable tests across different browsers and operating systems.
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.
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 over 3000 real environments. Try LambdaTest 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@latest
After Playwright installation, you’ll have a fully configured project with:
Let’s test a user registration flow on the LambdaTest 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 LambdaTest 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 LambdaTest.
We will run the same test scenario using the autoHeal capability provided by LambdaTest.
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: 'LambdaTest-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=LambdaTest-Chrome-AutoHeal
Pro-tip: You can also leverage Generative AI testing agents like LambdaTest 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 LambdaTest 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 LambdaTest 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.
On This Page
Did you find this page helpful?
More Related Hubs