From Maintenance Nightmare to Stress-Free Automation with Auto-Healing

Somya Goyal
Naukri Engineering
Published in
5 min readJun 29, 2023
Closeup photo of eyeglasses photo — Free Computer Image on Unsplash

How many times did you need to scrap your automation scripts just because the site or a feature has been revamped?

How many times you have faced the situation of rehandling your automated code due to selenium flakiness or just because the scripts are not running, in the same manner, the way they used to run on your local?

These all are very common problems that we face as a tester.

Seems so trivial but trust me they are not !! as it requires one’s time and effort that one can put into some other priority tasks.

Now, the question arises,

How can we solve this??

My answer will be through….. Auto-Healing

Before jumping to the part what is Auto-healing? How does it work? How impactful it is? Let’s first dive into the holistic approach that we all are doing in the current scenario.

A holistic approach to automation

Whenever the properties of the object are tweaked beyond the original configurations, traditional automation scripts may no longer be able to recognize it — which shuts down the process.

Object, in this particular context, is an item within a script with which the end-users interact to carry out a task.

Most of the time the reason for our scripts’ failure are:

  1. the changes in the HTML code
  2. Selenium flakiness leads to exceptions like elementnotvisible, Nosuchelementexception, ElementNotSelectableException, timeoutexception, and many more.

Due to this, our scripts get failed and to identify the cause we need to take the following steps:

  1. Firstly, we check the Jenkins console to find out the cause.
  2. And then we look into our local code and fix the locator changes/or other issues
  3. Then re-run the whole test suite and check its status.

which in itself is time-consuming and needs unnecessary efforts from the QA team.

Now, Let’s answer your questions one by one.

What is Auto-healing ?

Auto-healing automation, in essence, is automation within automation. It’s a remedy for failing automation test cases.

How does it work ?

The auto-healing automation, upon sensing changes in properties, holistically studies the attributes and properties of all available objects, scrapping similar objects on the page.
So that, whenever we face any exceptions, auto-heal code will generate the XPath based on other properties saved in the database for that element and our system then deploys a weighted scoring system to pick one that most resembles the previous object and continues running the automation script as well as updating the object properties, to avoid future script breaks.

Stages in the work flow

Flowchart : Workflow of Auto-Healing

If auto-healing is implemented in our code, then the following are the steps that are being followed:

  1. Run the test case and detect the object with an already-mentioned locator
  2. If the test case fails and throws an exception
  3. It generates the locators of the object from the properties that are already saved in the database against that element.
  4. Then re-run the test case with the generated locators
  5. Then sends a Mail notification

The process to generate locators:

Initially, when automation scripts get executed then as it traverses it extracts elements properties (such as id, class, text, and title) and saves them in the database against that element.

So that, if in the future any object’s property gets tweaked then our script will run and find its other properties, and based on that it creates several XPath.

Our script will continue to run and verify it for the generated XPath

And update the locators in the database itself according to the new properties.

for example, Let’s say there is one login page and we have created an XPath for the username field whose html content is :

<input type=”text” placeholder=”Username” name=”username” id=”email” class=”inp-md”>

for the above username, XPath written was //input[@id=’email’]

So when our script runs it will extract other properties of that element as well (here, it will extract its placeholder, name, id, and class properties)and store them in the database.

Now let’s assume due to page revamp the ‘id’ property gets changed, So in this case, when our script will run it’ll throw an exception and our healing code will start running and start making XPath with the properties that are stored and try to locate that object, the script will keep on creating XPath from the properties until it will find a suitable match and that’s how healing takes place. Also, the updated properties get saved in the database against that element.

There are two conditions under which we are sending the emails to the project owners:

  1. When our script is healed by the new locator made by our code. In this, we are sending mail to the stakeholders giving the information of the exception why the auto-healing script was run, and the new XPath through which the script was healed.
  2. When a script fails and our code is not able to heal due to some issues (e.g., due to stale element exception) then a mail is sent notifying the exception due to which the failure occur and telling them to look into that element.

So, to summarize the whole concept, whenever any script failure occurs and we are not able to detect an element then, in that case, auto-healing will occur and try to find the element by generating a new Xpath with its other attributes and after fixing it, will send all the details relevant to that element to required stakeholders like the exception and the new xpath with which it healed the script.

How impactful it is ?

With the implementation of auto-heal code, we have saved approximately 30000 min in the last six months!

Conclusion

I’m hoping this blog has given everyone an insight and a sense of what auto- healing can do to create new directions for the world of automation. If it were to be implemented, the tester could take a breath of relief as they’d probably lose interest in maintaining their scripts.

--

--