Chimera Technologies

How to eliminate object locator flakiness with Katalons new self healing feature

How to eliminate object locator flakiness with Katalon’s new self healing feature

Imagine you’ve developed an automated test script, and everything is functioning smoothly. But guess what? As time passes, the application evolves, elements change, and your once-flawless script begins to fail. Fear not, Katalon Studio has a smart feature: the Self-Repairing Mechanism.

 

Picture this: Our automated tests dynamically adapt to changes in the application. Yes, that’s the magic of Katalon Studio’s Self-Healing Mechanism!

 

In our web UI testing, the continuous addition of new page objects and modification of pre-existing identifiers has always been a challenge for any tester as this makes test scripts break easily, no matter how we would like to test or how much we know.

 

In this article, we are going to talk about the self-healing mechanism. It’s important in ensuring the stability and reliability of automated tests in Katalon Studio, even when things on the website change.

 

What is Katalon Studio?

Katalon is an AI-augmented software quality platform designed to simplify automated test creation and execution that helps teams to test websites, mobile, desktop apps and APIs.

 

Katalon Studio enables testers to write and manage test scripts more efficiently. One of the most standout features of Katalon Studio is its Self-healing mechanism. Since version 7.6.0, Katalon Studio supports the self-healing mechanism to tackle the issue of broken locators during execution.

 

What is Self-healing mechanism?

The Self-Healing Mechanism is a powerful feature offered by Katalon Studio, which is designed to tackle one of the most frequently encountered challenges in test automation – the NoElementFoundException. This generally means that our script is unable to find the specified locators.

 

But what reasons the NoElementFoundException in the initial place? This error generally arises due to failure to locate test objects, inability to load the selected test objects into the Document Object Model (DOM) or incorrect implementation of locator strategies.

 

The question that arises now is how we can avoid such errors in our automation scripts. Well, the good news is, Katalon Studio has effectively addressed this problem with its Self-healing mechanism.

 

The Self-Healing Mechanism continues to search for alternative options captured during recording, when a test automation script cannot find a test object. This way, instead of failing due to a NoElementFoundException, the script proceeds with the execution of the scenario steps.

 

The self-healing mechanism of Katalon Studio is an in-built system within the tool that is capable of automatically repairing itself. Before we explore how this feature can be practically applied in our automation testing, it’s essential to understand the theoretical aspect of the self-healing mechanism and how it operates.

 

Note: It’s important to note that currently, this mechanism is only employed in web-based automations.

 

How Self-healing works in Katalon Studio?

Katalon Studio’s self-healing mechanism is based on the use of smart object recognition and dynamic locators. The tool uses advanced image recognition algorithms to identify objects in the application under test and accurately locate them on the screen.

 

When executing a test, it compares the recorded properties of an object with the actual properties in the application. If there is a mismatch, Katalon Studio attempts to find the best match by adjusting the properties dynamically. This ensures that the test cases continue to run without failure.

 

Katalon Studio also provides image-based recognition. This involves capturing and comparing screenshots of the application during test execution. If an element cannot be identified using regular methods such as XPath, Attributes and CSS, Katalon Studio utilizes image matching to locate and interact with it.

 

Katalon Studio also provides an object repository that allows users to manage and organize their page objects. The repository provides a centralized location for storing object information, including locators, properties, and test data. This makes it easy for users to maintain their test cases.

 

Activating Self-Healing in Katalon Studio

The Self-Healing Mechanism is enabled by default when creating a web-based project in Katalon Studio. To verify the same,

 

Navigate to Project > Settings > Self-Healing > WebUI, and then check or uncheck the box Enable Self-healing execution.

 

During a web-based project setup in Katalon Studio, Self-Healing currently supports 4 locator methods.

 

1. XPath

2. Attributes

3. CSS Selector

4. Image

 

By avoidance, it will initially attempt to find the test object via XPath. If found, it will proceed with the following steps. If not, it will sequentially explore the other test object methods, continuing the process with the test object that matches successfully.

 

We can choose to use one or more of these element locator methods by selecting or deselecting the corresponding checkboxes. Furthermore, we can prioritize the order of alternative methods by moving them up and down, defining the type of test object it should first search for as an alternative. It will select an alternative test object based on the default order, if left unchanged.

 

For example, if Katalon Studio fail to identify the default locator of some web object, it will start examining in the following order.

 

First, it will look for the relative XPath. When the alternative XPath is located, the system seamlessly continues execution and prompts you later to make it the default.

If Katalon can’t find an element using its XPath, it tries other methods in this order: to attributes, CSS and image.

 

In an object view, we can decide the default Selection Method for locating that object during execution. This configuration makes ineffective the global programming in Self-Healing -> Web UI -> Test Execution.

 

When Should the Self-Healing Mechanism Be Avoided?

The primary purpose of the Self-Healing Mechanism is to interact with web objects, and it is not designed for verification or comparison methods. In cases requiring such actions, we can utilize the Self-Healing menu to exclude methods/objects by specifying the relevant Keywords.

 

Self-healing Insights – Applying the Self-Healing Mechanism

By utilizing alternative objects in place of unavailable test objects, all our tests have been successfully executed, as illustrated below.

 

During test execution, if a test object creates an issue during test execution, a SELF-HEALING warning will appear in both the “Console” and “Log Viewer” tabs.

 

Upon test completion, the Self-Healing Insights tab will present alternative choices for test objects. In this section, we can select the preferred test object.

 

In this tab, we will find details about the unavailable test object (Broken Locator), the used alternative test object (Proposed Locator), the method used to locate it (Recovered By), and a screenshot of the element.

 

Verify if the located object aligns with our expectations. We have the option to choose one or multiple suggested locators and then proceed to:

 

Approve: To permanently implement the changes.

Discard: To Decline the suggestion.

 

Conclusion

The mechanism of self-healing, selecting and prioritizing the different selection methods in Katalon Studio using XPath, Attributes, CSS and image as flexible alternatives for broken locators helps in reducing test flakiness by offering backups for a broken or missing object locators when it collapses to locate that web element. We can then update the broken objects with new locators with just a few clicks, lessening our efforts for test maintenance.

 

About Author 

Harshitha T. is a Senior Software Engineer at Chimera Technologies, specializing in Automation, possesses expertise in testing and ensuring the quality of web applications using Protractor and mobile applications using Appium and Browser Stack. Passionate about exploring the cutting-edge advancements in AI and maintains a keen interest in staying updated with the latest trends in technology and is committed to delivering high-quality software solutions. Currently, involved in testing and ensuring the robustness of web and mobile applications, contributing to the seamless integration of AI technologies into the testing framework.