Healenium: Self-Healing Library for Selenium Test Automation

Anna Chernyshova
Geek Culture
Published in
4 min readAug 28, 2021

--

All automated UI tests sooner or later catches NoSuchElementException due to the changed layout and broken selectors. As a result, test crashes and the CI build turns red. In this article I’m going to bring an overview of a self-healing library called Healenium, it’s capabilities and purpose of usage.

Healenium is an AI-powered open-source library that improves the stability of Selenium-based tests, handles changes of updated web elements automatically and helps to overcome the problem of UI autotests instability using self-healing mechanism.

Healenium brings significant value to business:

  • It minimizes test automation code maintenance time so the team can focus on increasing coverage.
  • As healing performs in runtime — automated End-2-End tests will be stable and UI changes will not affect them anymore.
  • Tests provide an accurate quality feedback and CI pipeline will fail only in case of product-related issues.

What’s inside?

Under the hood, Healenium uses a type of Machine Learning algorithm that analyzes the current web page for changes: modification of Longest common subsequence algorithm with weight. It solves the problem of finding the longest subsequence common to all sequences in a set of sequences with extra weight for tag, Id, class, value, other attributes. So if an element changes its place in DOM or has a new id, Healenium will find it and generate new locator.

How Healenium works?

Let’s take a look at the example.

Imagine we are trying to find our element on UI by id #button.

As we see, the element was found successfully. Healenium saves a successful locator in the storage to use it as a baseline for the next test executions

Now imagine that the UI changed and new id for the target element is a #green_button. But the test team is not aware of the changes and didn’t update the test automation code base.

So we are trying to find the target element by the old id #button and as a result element was not found.

With the standard Selenium implementation test will fail in this situation but not with Healenium. Healenium catches NoSuchElement exception, triggers the Machine Learning algorithm, passes the current page state, gets previous successful locator path, compares them, and generates the list of healed locators.

It takes the locator with the highest score and performs an action with this locator.

As we see the element was successfully found and test passed

After the test is run, Healenium generates the report with all detailed information about healed locator, screenshot and feedback button on healing success

If healing was successful, we can update our automated test using the Healenium Idea plugin. Plugin looks for healings and updates test code with the healed locator

Healenium infrastructure contains several components:

healenium-web — Java library that integrates with Test Automation Framework

  • Implements Selenium WebDriver
  • Overwrites findElement() method
  • Catch NoSuchElementException
  • Activates LCS algorithm in Tree-comparing library

healenium-backend — docker container that manage healings and includes PostgreSql database that stores element info

  • Save reference element path to storage
  • Get reference element path from storage
  • Collect data for report generation

healenium-report-gradle, healenium-report-maven — Gradle and Maven reports that listens to the triggered test session and generates report link after each tests suite run

Tree-comparing — LCS algorithm implementation

  • Get current DOM state
  • Search in current state for the best subsequence
  • Generate new locator (CSS, XPath, id, etc.)

healenium-idea — Intellij Idea Plugin that search for healing results in DB and updates locator in the codebase

Advanced Healenium features:

  • Multi-project work — you can have several Test Automation Frameworks for different projects connected to a single Healenium-backend instance.
  • Parallel test execution — do not limit yourself with 1 thread
  • Test execution on the remote infrastructure — you can run your tests on Selenium Grid or Selenoid
  • Iframes, JS Actions support — for advanced testing
  • Integration with selenium-based frameworks like Selenide for your test implementation
  • Applicable for mobile testing with Appium.
  • Test execution results can be stored in the Report Portal with the help of healenium-RP extension

Conclusion

I would like to highlight that Healenium can be a perfect solution to solve the problem of UI autotest instability for projects with:

  • Frequent User Interface changes
  • User Interface generated by Content Management Systems
  • Test automation based on Selenium WebDriver
  • Project with the need of Localization testing or Testing under Internet Explorer

Examples of Healenium usage with different Test Automation frameworks can be found here in the official GitHub repo

--

--

Anna Chernyshova
Geek Culture

Quality Architect with progressive experience in automated testing. Creator of BDD test automation library Akita and Self-healing library Healenium