Skip to main content
Experience faster, smarter testing with BrowserStack AI Agents. See what your workflow’s been missing. Explore now!
No Result Found
Connect & Get help from 6000+ developers on our Discord community. Ask the CommunityAsk the Community

Use AI Self-Heal for your Playwright tests running on BrowserStack Automate Icon indicating AI feature

Automatically recovery your failed Playwright tests using AI on BrowserStack Automate.

Self-Healing automatically detects when a locator no longer works and intelligently finds the right element using historical context and AI signals. Instead of failing immediately, BrowserStack recovers the test and records what changed — reducing false failures and keeping builds green as the UI evolves.

What is BrowserStack Self-Heal?

The following video explains how BrowserStack’s Self-Heal feature works:

Try out the Self Heal feature using the Automate sample repo.

When to use Self-Healing

  • Your tests frequently fail due to UI or locator changes.
  • UI Refactoring and redesigns happen often across teams.
  • Flaky tests due to NoSuchElement exceptions are common.

Use Self-Heal to reduce build instability and debugging time.

Key features

  • findElement command healing: Heals broken locators used in findElement commands.

  • Generate resilient locators as output: Provides healed locators that can be used in future test runs.

  • Build level healed selector report: Provides insights into healed selectors at the build level. (Coming soon)

Prerequisites

  • Your account must have BrowserStack AI enabled to use the AI Self-Healing feature. For more information, see our documentation on how to activate AI preferences.
  • Self-Healing Agent is available only on Automate Pro plan.

Enable Self-Heal

To enable the Self-Heal feature, set the selfHeal capability to true in your test configuration file.

AI Self Heal feature will not work on your Chrome tests if you have set the browser to operate in incognito mode.

The Self-Heal feature is currently supported on the following browsers.

Platform Supported browsers
Desktop Chrome v126 and above
Edge v126 and above
All Playwright Chromium bundled browsers

If you are using BrowserStack SDK, you can set the following capabilities in the browserstack.yml file:

browserstack.yml
Copy icon Copy

You can organize your Playwright tests with the self-heal capability:

BrowserStack SDK is a plug-and-play solution that takes care of all the integration steps for you. It is the recommended method for integrating your Playwright project. To know more, visit the SDK core concepts page.

Use the selfHeal capability to set self-heal as shown in the following code sample:

MutableCapabilities capabilities = new MutableCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("userName", "YOUR_USERNAME");
browserstackOptions.put("accessKey", "YOUR_ACCESS_KEY");
browserstackOptions.put("selfHeal", "true");
capabilities.setCapability("bstack:options", browserstackOptions);
var capabilities = {
	'bstack:options' : {
		"userName" : "YOUR_USERNAME",
		"accessKey" : "YOUR_ACCESS_KEY",
		"selfHeal" : "true"
	}
}
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("userName", "YOUR_USERNAME");
browserstackOptions.Add("accessKey", "YOUR_ACCESS_KEY");
browserstackOptions.Add("selfHeal", "true");
capabilities.AddAdditionalOption("bstack:options", browserstackOptions);
$caps = array(
	'bstack:options' => array(
		"userName" => "YOUR_USERNAME",
		"accessKey" => "YOUR_ACCESS_KEY",
		"selfHeal" => "true"
	)
)
desired_cap = {
	'bstack:options' : {
		"userName" : "YOUR_USERNAME",
		"accessKey" : "YOUR_ACCESS_KEY",
		"selfHeal" : "true"
	},
}
capabilities = {
	'bstack:options' => {
		"userName" => "YOUR_USERNAME",
		"accessKey" => "YOUR_ACCESS_KEY",
		"selfHeal" => "true"
	}
}

How Self-Healing works

Each time your test interacts with an element, Self-Healing Agent securely stores key information about that element — including its locator, nearby attributes and the structure of the DOM.

During future test runs, if the original locator no longer resolves, Self-Healing steps in and the following process takes place:

  • Detects a broken locator.
  • Evaluates the latest success context.
  • Generates the alternate healed locator.
  • Applies the resilient locator and continues the test run.

Self-Heal requires at least one successful test execution with the same elementIdentifier to capture the correct element context. For example, if your successful test uses .text='Log in' but the failed test uses .text='log in', healing won’t work because the elementIdentifier differs. To ensure healing works:

  • Use consistent elementIdentifier values across successful and failed builds.
  • Make sure your success case runs first so that BrowserStack can register the element context before attempting to heal failures.

Self-Healing Workflow

  1. Build listing- list of all your builds.
  2. Build insights- detailed insights of self-healed tests in a build.
  3. Test listing- list of all tests in a build.
  4. Text logs- detailed logs of a test including self-healed locators.

All your Builds which have Healed-Selectors will appear with the AI icon next to its name:

Self-healed Session

Builds Insights page have 2 elements:

  • The Self-Healed Test CTA on Build Summary widget
  • Self-Healing Insights widget Build insights widget

Self-heal insights widget

All your tests that are recovered by Self-Heal appear on the dashboard marked by the Self-Heal icon as shown in the following image:

Self-heal recovered

You can view these self-healed resilient locators in the Text Logs tab of your session masked by the Self-Heal icon

Self-healed resilient locators in the text-logs tab

You can filter the Text Logs to only view the self-healed locators as shown in the following image:

The Text Log filter will only be available if selfHeal is enabled for your test session.

Self-healed text-logs

BrowserStack recommends you to replace the locators in your test script with self-healed locators to improve the stability of your tests.

Self-Heal limitations

Although the Self-Heal feature is engineered to handle a broad spectrum of issues, it comes with its own set of limitations, such as:

  • Some Performance overhead
    Healing adds extra analysis during execution. The impact is usually small, but it should complement — not replace — good test design and error handling.

  • Not all failures can be healed
    System failures, WebDriver issues, and situations where the element truly no longer exists cannot be recovered. These tests will (correctly) fail.

Self-Heal for Playwright is presently in limited capacity and does not support all the feature capabilities as Selenium.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle