Skip to main content

Use AI self-healing for your automated tests

Learn how to use AI self-healing feature on your tests with BrowserStack Automate.

BrowserStack’s self-healing feature for automated tests enables automatic recovery from locator changes or sub-optimal locator strategies during test execution. This feature enhances test suite robustness, reduces test flakiness, and improves reliability.

The selfHeal feature is currently in beta and is available for Automate users running the Selenium framework with the following desktop browsers:

  • Chrome v92 and above
  • Firefox v72 and above
  • Edge v92 and above

Enable self-healing

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

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

browserstack.yml
Copy icon Copy snippet

You can use Selenium 4 capabilities to set self-healing using 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"
	}
}

At least one successful execution is required with self-heal to register the correct element context.

When the selfHeal capability is set to true, BrowserStack utilizes a rule based algorithm to identify the locators. If this strategy fails, it uses an AI based algorithm to find the locators.

To leverage AI for self-healing, check out our documentation on how to activate AI preferences.

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-healed Session

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

Self-healed Locator

You can filter the self-healed builds using the builds filter and selecting the Healed option under Self-Healing dropdown.

Build view filter

You can also filter your self-healed sessions using the sessions filter and selecting the Healed option under Self-Healing dropdown.

Session view filter

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.

Text Log Filter

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

How Self-heal Works

The self-healing functionality of Selenium Locator represents an advanced approach in test automation aimed at mitigating the volatility of inconsistent tests. This system intelligently adjusts locators by consolidating attributes and context, thereby promoting robustness and flexibility. Throughout runtime, it continuously observes the web page to detect any changes in the Document Object Model (DOM).

Once an element is successfully located on the page, its DOM path is logged for future reference. In the event that the same element is subsequently referenced on the page but cannot be found, the system analyzes the current page state and generates new locators for modified elements based on past references.

The self-healing feature automatically detects new locators that were changes by web elements and continues the test execution.

Self-heal advantages

Self-healing has a crucial role in streamlining the test automation process. Following are its advantages:

Stable builds: BrowserStack’s self-healing feature is smart—it adjusts to changes and carries out tasks intelligently. It uses artificial intelligence and machine learning to make sure automated tests can handle variations in applications or environments smoothly. This means fewer errors in Continuous Integration (CI) pipelines and smoother developments overall.

Intelligent Test Automation: BrowserStack’s self-healing capability guarantees test stability and consistency, even when confronted with small alterations in the UI of the web application. With its AI-powered feature dynamically adapting to these changes, glitches that used to disrupt testing are handled effectively while ensuring reliability; thus delivering a stable outcome for your entire suite of tests quickly.

Streamlined Test Maintenance: An ongoing challenge in test automation is the requirement to frequently modify and upkeep testing scripts as application interfaces evolve. By utilizing BrowserStack’s self-healing feature, adjustments are automatically made by the system which results in less manual intervention needed to revise testing scripts; resulting in a reduction of both time spent and resources used.

Self-heal limitations

Although the self-heal feature is engineered to handle a broad spectrum of issues, it comes with it’s own set of limitations, such as:

Performance: Enabling self-heal may slightly impact test execution time due to additional checks and recovery mechanisms, but such a performance impact is typically minimal. Rather than replacing good test design and error handling practices, the self-heal feature serves as an enhancement to increase your suite’s robustness. It’s crucial always to ensure well-designed tests with proper error handling in place while regularly reviewing for issues that could be masked by the self-heal function.

Non-recoverable errors: Self-heal is incapable of recovering from certain error types, such as WebDriver initialization errors or system-level failures, which are classified as non-recoverable.

Test accuracy: Although self-heal may decrease the occurrence of test inconsistency, it can conceal genuine problems in your web application or test scripts. It is crucial to examine the logs and comprehend why a particular test requires healing.

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