Use AI self-healing for your Selenium tests running on BrowserStack Automate
Enable automatic recovery of your failed Selenium tests using AI on 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 Self-heal feature is currently in beta and is available for the Selenium framework and supported browsers. If you are facing any issues using the feature, contact us.
Enable self-healing
To enable the self-healing feature, set the selfHeal
capability to true
in your test configuration file.
The self healing feature is currently supported on the following browsers
Platform | Supported browsers |
---|---|
Desktop | Chrome v92 and above Firefox v72 and above Edge v92 and above |
Mobile |
iOS All browsers except Safari minimum requirement - iOS 14 Android All browsers |
If you are using BrowserStack SDK, you can set the following capabilities in the browserstack.yml
file:
You can use either Selenium 4 or Selenium Legacy JSON to organize your tests
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 project. To know more, visit the SDK core concepts page.
Use the selfHeal
capability to set self-healing 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"
}
}
Use the selfHeal
capability to set self-healing as shown in the following code sample:
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("userName", "YOUR_USERNAME");
caps.setCapability("accessKey", "YOUR_ACCESS_KEY");
caps.setCapability("browserstack.selfHeal", "true");
var capabilities = {
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"browserstack.selfHeal" : "true"
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.AddAdditionalCapability("userName", "YOUR_USERNAME");
capability.AddAdditionalCapability("accessKey", "YOUR_ACCESS_KEY");
capability.AddAdditionalCapability("browserstack.selfHeal", "true");
$caps = array(
"userName" => "YOUR_USERNAME",
"accessKeyild" => "YOUR_ACCESS_KEY",
"browserstack.selfHeal" => "true"
);
desired_cap = {
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"browserstack.selfHeal" : "true"
}
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["userName"] = "YOUR_USERNAME"
caps["accessKey"] = "YOUR_ACCESS_KEY"
caps["browserstack.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:
You can view these self-healed locators in the Text Logs tab of your session masked by the self-heal icon
You can filter the self-healed builds using the builds filter and selecting the Healed option under Self-Healing dropdown.
You can also filter your self-healed sessions using the sessions filter and selecting the Healed option under Self-Healing dropdown.
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.
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
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!