When automating Web tests through the UI, we know that, as the application grows, the number of elements in the graphic interface will probably increase, and, with them, that the locators we use to interact with them will undergo constant changes.
Throughout the test automation maintenance process, updating locators for web elements is a recurring activity that takes a considerable amount of time.
The concept of self-healing is a solution implemented by several test automation tools to deal with the challenge posed by the constant changes to UI elements within applications. This ability to auto-repair locators offers the testing team an advantage by reducing the time and effort involved in maintaining tests, ensuring that they run seamlessly and minimizing any possible interruptions during their execution.
How does this mechanism work?
In broad terms, automated scripts are composed of a series of commands or steps that, as a whole, represent the complete flow for every test. These commands are executed over UI elements of the system under test using the localization information for each element, which is usually referred to as a “locator”. This is how test scripts end up depending on the information included in these web locators to correctly execute every step. As the application evolves, and UI elements undergo changes, it is inevitable for locators to change, and it is necessary to update them in order to avoid the scripts failing during execution.
The self-healing mechanism is meant to solve this problem by identifying changes undergone by these web elements as the application evolves, detecting changes in the element properties and automatically updating their information with the new locators in order for the automated test cases to continue working without any issues.
Clearly, the main benefit of self-healing is having the ability to have locators updated automatically and have scripts execute correctly with each system version, thus minimizing the time and effort involved in maintaining tests and allowing the testing team to dedicate the time saved to creating new tests.
Upon further examination, we can identify other related benefits stemming from this that it might be interesting to mention:
- A smaller number of failed tests: tests can fail and, as automation testers, we are aware of that. Many times, the reason behind these failures is simply that the UI has changed, and our tests have not. Using the self-healing functionality, we reduce the risk of our tests failing due to problems related to locators, thus ensuring a higher stability during test executions.
- Higher stability in the location of elements: the instability of tests is a recurring issue we face as automation testers, and it is difficult to determine when scripts are stable enough for us to start executing them. Errors such as “NoSuchElementException” are the reason why there is such an instability; this particular error is caused by not being able to locate an element in the UI, and we do not have much control over it. With self-healing locators, scripts are updated with the application, the execution flow is more stable, and there is a lower tendency for tests to fail because of element locator issues.
Katalon Studio’s self-healing model
In Katalon Studio version 7.6, the “Auto-healing Smart XPath plugin” complement was included in the application. This complement made it possible for locators that were not working during the test execution to be identified, and suggested actions that the user could take to fix them. As its successor, this new self-healing version was developed and included in the Katalon Studio IDE.
This new mechanism is able to determine the status of the tests, detect errors with locators, analyze them and offer a solution to fix scripts automatically, with the user only having to approve the change or rule it out and deal with the problem manually.
If the self-healing feature is enabled, tests become smarter and automation testers have to worry less and less about executing their tests with new system versions coming out. At the same time, confidence in automated tests increases because, when a test case fails, it does so with good reason, and those reasons reflect on the quality of the developed product.
Katalon Studio supports four selection methods when designing automated test scripts in the web UI, identifying the locator information when using the recording or object spy features.
These selection methods are: XPath, HTML attributes, CSS selectors and image recognition.
If necessary, users can modify the order of these selectors for the execution. For XPath in particular, it is necessary to do some extra configuration to let Katalon know how to go through the list of available locator options when the main locator is failing.
By default, the self-healing mode is enabled when a new project is created. The user can enable or disable this mode by going to Project > Settings > Self-Healing > Web UI and changing the option in the Self-Healing tab, or simply by clicking the Self-Healing icon in the tool bar. If necessary, self-healing can be excluded for specific objects by using specific keywords and thus preventing Katalon Studio from analyzing them and executing the self-healing process over those objects.
When executing tests, Katalon Studio will attempt to locate web elements based on the locator selected by default, and, if the locator does not return a web element, it will use self-healing and attempt to locate it with the information it has about the object.
After the tests are executed, if Katalon Studio applied self-healing to any element, the information will be displayed in the Self-Healing Insights tab. There, you can see all objects for which the locator had to be healed; this information will be stored temporarily until the user decides what action to take (accept or discard the change).
The Self-Healing Insights tab displays the following information:
- Test Object ID: the ID of the object with an obsolete locator.
- Broken Locator: the locator for the element that was not found during execution.
- Proposed Locator: the alternative locator Katalon Studio used to find the web element during execution.
- Recovered By: the method used by Katalon to detect the element.
- Screenshot: Katalon captures an image of the web element that the user can look at to verify that the correct element was found. The image can be examined by clicking “Preview”.
- Check box: a checkbox column allows the user to select multiple elements at the same time to take action over them.
If the user decides to approve the change, the locator proposed by Katalon Studio becomes the new default locator for the element. Otherwise, if the user decides to discard Katalon Studio’s suggestion, the object information is not altered.
To complement the aforementioned mechanism, Katalon introduces another tool in the 7.8 version to reduce the cost of maintaining tests called “time capsule”.
This new feature makes it possible for an HTML and CSS snapshot of the website at the exact moment the failure occurred to be stored. Thereafter, it is possible to open the snapshot in the browser and locate the problem immediately.
How does it work?
An error during the execution of a test case implies that the test case must be re-executed until reaching the point where the failure occurs (whether it is a bug in the system or an outdated locator), which takes a considerable amount of time.
With this new feature available in the Katalon Studio IDE, it is not necessary to execute the whole test case manually to reach the failure because Katalon stores a web snapshot of the error, generated with the same HTML and CSS in the original website.
To access this view, simply click the “Click here to fix broken Test Object” link displayed in the log viewer details.
After clicking the option, Katalon will display a web view using the default browser and automatically start the object inspector for the specific object with a broken locator.
This allows for the object to be updated with the new locator quickly without having to re-execute the failed test or to manually navigate to the page where the failure is occurring. At the same time, it is possible to inspect and store other elements in the same view, therefore taking even more advantage of the time allocated for the maintenance of tests.
The new self-healing mode available with the latest version of Katalon promises to improve the scope of this mechanism and make it easier to update web locators, offering a much more efficient way to handle changes to the application under test.
To complement this mechanism, Katalon Studio offers the time capsule with its latest version to even further reduce the effort required to maintain and correct locators, especially when test cases have lots of steps. These features reduce the number of test maintenance tasks considerably, decreasing the probability of the test failing when being executed and increasing their stability.
This approach of a smarter execution and more automated error correction mechanisms make it possible for Katalon Studio to accelerate development cycles and continuous integration with tools that are increasingly automated and increasingly faster.
In the following Katalon post you can expand the information.
Also a specific webinar for Katalon Studio 7.8.