Healenium: Run test with healing locators
Self Healing
Selectors in Automated UI are a source of frustration: tests “break” due to changes in layout. As a result, UI tests are unreliable as part of the testing pipeline and Continuous Testing itself. Layouts change, causing test crashes and build to turn “red.”
Healenium allows you to automatically overcome the problem of automation test instability and spend less time supporting tests. It now also works for Mobile Automation.
What is the Healenium?
Healenium is a testing framework extension that improves the stability of Selenium-based tests. The use of machine learning (ML) algorithms for detecting webpage changes will assist you in finding controls (new locators) for updated webpages and fixing your tests in the runtime. Self-healing capabilities allow for the replacement of a “broken” locator with a new value and the repair of the test during run time. It is open-source and available on GitHub.
Getting starting with Healenium
- Add Maven dependency
To use Healenium we need to add Healenium web dependency to our maven project.
<!-- https://mvnrepository.com/artifact/com.epam.healenium/healenium-web -->
<dependency>
<groupId>com.epam.healenium</groupId>
<artifactId>healenium-web</artifactId>
<version>3.2.4</version>
</dependency>
2. Then we need to add Healenium properties file.
recovery-tries=1
score-cap=.6
heal-enabled=true
serverHost=localhost
serverPort=7878
imitatePort=8000
Here, You can read what we define using the above property file.
recovery-tries — a list of potential healed locators
heal-enabled — Toggle the flag to enable or disable healing. You can also set this value using -D or System properties, for example, to disable healing for the current test run: -Dheal-enabled=false
score-cap — score value to enable healing with a predefined probability of match (0.6 means that healing will be performed for newly healed locators where the probability of match with target one is greater than 60%).
serverHost — ip or name where hlm-backend instance is installed
serverPort — port on which hlm-backend instance is installed (7878 by default)
imitatePort — port on which imitate instance is installed (8000 by default)
3. Init driver instance of SelfHealingDriver
static protected SelfHealingDriver driver ;
WebDriver delegate = new ChromeDriver();
driver = SelfHealingDriver.create(delegate);
Here, We declare delegate and then create self-healing driver
4. Use standard By/@FindBy to locate your elements
By menuButton = By.xpath("//span[@class='navbar__tutorial-menu--menu-bars']");
driver.findElement(menuButton).click();
5. To disable healing we can use annotation — @DisableHealing
6. Add hlm-report-mvn plugin to enable reporting
To configure plugin:
<build>
<plugins>
<plugin>
<groupId>com.epam.healenium</groupId>
<artifactId>hlm-report-mvn</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>hlmReport</id>
<phase>compile</phase>
<goals>
<goal>initReport</goal>
</goals>
</execution>
<execution>
<id>hlmReportB</id>
<phase>test</phase>
<goals>
<goal>buildReport</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
URL: https://github.com/healenium/healenium-report-mvn
7. Add hlm-idea plugin to enable locator updates in your TAF code
URL: https://github.com/healenium/healenium-idea
7. Run Test with healing :)
Healenium dependency URL: https://mvnrepository.com/artifact/com.epam.healenium/healenium-web
Healenium documentation: https://healenium.io/