This course demonstrates how Katalon Studio fixes broken object locators during test executions, without any manual effort involved. Equipped with Self-Healing, Studio automatically finds and uses pre-configured alternative locators to identify web elements, preventing tests from breaking.
During 3 chapters, you will learn about:
Note: You can download and use the sample project we used in this course here: https://github.com/katalon-studio/self-healing-demo
Hi and welcome to the first chapter. Let's start off with the mechanism of Self-Healing, how it really works to reduce the flakiness of your tests, before jumping into all the details and demos. The sample project that I will use in this course can be found in the Course Overview section for you to download.
With Self-Healing enabled, when Katalon Studio fails to identify an object via its default locator, it will continue to search for other pre-configured alternative locators to interact with that object. Thanks to this, the test execution can still be running rather than failing due to Unable to Find Element errors. Once the broken-locator object is ''self-healed,'' Studio will automatically continue to apply the working alternative for the remaining tests in the same execution time.
After your tests have completed executing with the final status as pass, the alternative locator will be proposed as a permanent replacement for the broken one. And with a simple click of Approve, it will be automatically updated as the new test object locator, without having to change anything in the relevant test cases.
Looking at this demo, what I have here is a test suite collection, including 3 test suites, each containing a typical automated end-to-end test case. They all interact with the same web elements, which are the Book Appointment button, Password textbox, and the Booking button. Now, let's run this test suite collection in both the sequential and parallel mode with Self-Healing on, and see how it goes.
First off, sequential execution. Running tests sequentially just means that each test will run one by one, where the following test case or test suite will start running once the one before it has finished. What's going to happen is the broken object locators in test case number 1 will be automatically healed with the replacement of new working locators. And the working alternatives will continue to be used for 2 other test cases during the runtime.
Our execution is finished. Let's check the Log Viewer, starting off with the first test case. The Book Appointment button in step 3 was initially not found by the default Xpath. So, Katalon Studio located and applied another Xpath alternative, which has prevented the test from failing. Same thing for the Password textbox in step 5 here.
Moving onto the next suite, the second test case. Steps 3 and 5 automatically used the working locator for the elements (the button and textbox) which were healed in the previous test suite. And at step 13, the object was identified for the first time, so the process of Self-Healing was triggered instantly. Finally, in the last test suite. Since every broken object had been healed in the first two suites, it simply used those working alternatives to run the test, without having to go through the Self-Healing process again.
Let's move to the Self-Healing Insights tab! You can then see the list of alternative locators for the 3 broken objects. If you want to use them as the new default locators for corresponding elements, simply click on the Approve button. After the update, if you run this test suite collection again, even with Self-Healing turned off, the tests would still run successfully, without any broken object issues.
Now, what would happen if the test suites run in parallel? Will Self-Healing still work fine? Or it will fail? Let's find out by running this collection in parallel mode. Simply switch it to Parallel, and execute. Alright, they are up and running. What's happening is these tests are being executed simultaneously, and whenever a test step encounters a broken object first, it will be independently ''healed'' with a working alternative locator.
The following steps in the same test case, or in other test cases will know to interact with the same element that was previously healed with a new locator, rather than starting to self-heal again. As you can see here, all the test suites have passed. Like previously, you can also have the option to update the broken locators with the proposed alternatives. Although the way that it operates is slightly different from the sequential mode, Self-Healing can still work perfectly fine in parallel executions without duplicating the work.
That's the end of our quick demo of the mechanism. All in all, Self-Healing saves you tons of time, not only for execution stability but also for your test maintenance, especially when your web application and its front-end elements go through frequent changes or updates in Agile projects.
Hi and welcome back! So, you've understood the mechanism of Self-Healing. Now, let me show you how simple it is to set up in Katalon Studio. Please note that Self-Healing is only available for Web UI testing and Studio version 7.6 onward. If you're new, then you can download the latest Studio version from Katalon.com or you can always find the latest update in Katalon Studio by navigating to Help > Check for Updates.
I've also included a link in the Course Overview section for you to download the sample project that I'll use in this course. Feel free to pause this video to prepare and practice as you learn. I have all my test cases and objects ready. In Studio, Self-Healing is enabled by default. But to turn it ON or OFF, there are two ways.
The simplest way is to click on the Self-Healing icon on the toolbar. If you see Disable Self-Healing, it means that Self-Healing is active and you can click on that toggle to turn it off. And vice versa. If it shows Enable Self-Healing, that means it has been turned off. So click Enable to turn it on. Another way is to go to Project > Settings, under the Self-Healing section, click on the Web UI. In this window, you have the option to enable or disable Self-Healing by checking on this checkbox.
And right below is the section for locator setup. Katalon Studio's Self-Healing mechanism currently supports 4 element locator methods: XPath, Attributes, CSS Selector, and Image. You can decide to use one or multiple methods for the Self-Healing function, by simply checking the boxes on the right.
You can also prioritize them by dragging and dropping or using the Move up and Move down buttons above. At this point, you may ask, ''what order would be the best for my case?'' That's a good question. It highly depends on the application under test and the elements you are using.
Let's go through these methods so you can understand and create an order that works best for your case. Let's take this current priority order as an example. Since XPath is on top, when Katalon Studio fails to identify an object via its default locator method it will look at XPath. Let's say the default is XPath and it doesn't work, Studio will continue to search and use its robust neighbors, meaning the other relative Xpaths, if there is any.
If Self-Healing successfully finds a working Xpath alternative to interact with that element, the test execution continues and later Self-Healing will suggest the alternative as a permanent replacement for the broken default locator. Otherwise, Studio will continue to search for Attributes. And the same process will repeat again for Attributes, then CSS Selector, and finally Image.
Particularly for Xpath and Attributes, a list of alternative locators can be generated automatically when you use Record & Playback or Object Spy to capture web elements and their properties. Alternatively, you can also use Studio's intuitive UI to add the locators manually, without doing much coding. Doing it this way saves you loads of time compared to when working with open-source libraries.
In some scenarios, you don't need the test engine to try out different locators to find a non-existing object, especially for certain steps to verify. So, what you can do is add specific keywords in this section at the bottom here, and the test objects associated with such keywords will be excluded from the Self-Healing mode.
For example, I will add the VerifyElementAttributeValue keyword to the exception list, then click on Apply and Close. And here I have a test case, where step 6 verifies the attribute value of the test object Username. It has the keyword VerifyElementAttributeValue. Now, Let's run this test to see the result.
For many keywords and commands like Click() or Sendkeys(), we need to successfully identify the test objects to interact then take action. That's why it is necessary to have backup locators when the defaults aren't working to reduce false positives.
However, for keywords and commands to verify value or for assertions, you need to evaluate the exact object's locator and its value. So, when the locator is broken or the element cannot be found, the test should fail right at that test step or keyword, rather than passing by using other alternative locators. That's why Katalon Studio excludes verifyElementPresent and verifyElementNotPresent from the Self-Healing by default. So here, when step 6 is running, the Username object is not healed automatically since it was excluded from the Self-Healing mode. And the test failed as expected.
During test executions, Self-Healing automatically finds and uses working alternatives for broken object locators, preventing your test cases from failing. After that, it will propose those alternatives as permanent replacements for the broken ones, like you're seeing them here in the Self-Healing Insights section, next to the Log Viewer tab.
All the details are listed out for you to review, including the Test Object ID, Broken Locator or the default locator that failed to detect the object during execution, Proposed Locator which is the alternative locator, Recovered By which is the method of the working alternative like Xpath or CSS Selector which successfully located the web elements, the Screenshot section is where Studio puts the screen capturing a test object once it is found by an alternative locator, just click on the Preview link here to see the healed object, finally, Selection is where you can choose the locator proposals to discard or approve as permanent replacements for the broken locators.
Let's take this first line as an example. This button's default locator is Xpath, and it is healed with a CSS Selector, which is the proposed locator. Since it solved my previous issue of object flakiness, I'll click Approve. Bam! Studio automatically replaced the broken Xpath with CSS Selector.
Let's go ahead and check. This button's selection method has been changed to CSS Selector, which will be used permanently for the next test executions, regardless of whether Self-Healing is active or not. Whereas if you already know why the element's locator is failing and have a specific value to replace it, you can choose to Discard Self-Healing proposals and go on updating the object with your value manually.
Well, that's everything you need to know to set up Self-Healing in Katalon Studio. In the next chapter, we'll run some demos to see how it actually works with different object locating options. See you then.
Hi, glad to have you back! Enough said with the theory and precondition setup. Let's move on to see how Self-Healing actually works in Katalon Studio. For this first demo, I will use this test case sample, Web 02. As mentioned earlier, you can also download these samples in the link I've included in the Course Overview section.
Alright, our test case has three test objects, the Make Appointment button, Username, and Password textbox, which I have modified their default locators to break them. For this button, the default locator is Xpath and I have added 'Katalon-Studio-team-has-broken-this-locator.' Below, in the Object's Xpaths section, there are other Xpath locators, where the first two options are broken as well. But our third one, Xpath:link, will be the one that works and later be used to heal this button.
To create these Xpath locators, you can add them manually when designing your test cases, or you can use Studio's built-in Object Spy or Record feature to generate them automatically when capturing the web elements. For the Username and Password text boxes, their default locators are also incorrect, meaning Studio will have to find other working alternatives for them as well.
Back to our test case. Without Self-Healing enabled, our test would surely fail at step 3, since it wouldn't be able to find the Make Appointment button using the broken locator. So, before running this, let's have a check on our Self-Healing settings to make sure it's enabled. And since we place Xpath as our first priority, Studio will search for other available Xpath alternatives before looking for other types like Attributes, CSS, and Image. Alright, time for some action. Let's run this test case. Through the Log Viewer, you can see that Self-Healing is working as the test steps are being executed.
Let's have a closer look at our healed objects. For the button at step 3, it was initially ''unable to find the element located by Xpath,'' which was the default locator. Then, it automatically searched for other Xpaths until it found a working alternative, which was the third Xpath:link, as we expected earlier. The same process applied for Username and Password boxes at steps 5 and 7.
So for these 3 steps, we can see a more detailed look in Self-Healing Insights. If it hasn't appeared on-screen, click on the refresh icon and wait for a few seconds. Ah! Here they are! There are 3 objects listed here, with the details of their broken Xpath default locators and their proposed alternatives. Check on all the boxes and click Approve and you'll see the green message of '3 broken test objects recovered.' Easy peasy!
Let's see what's changed in our test objects. Their selection methods are still Xpaths, but their locators have been updated to new ones. These replacements are permanent. Now, even with Self-Healing disabled, this test case (or any other test cases) will start using the newly updated locators to identify these objects and significantly lower the chance of them failing due to flaky locators.
In this next chapter, we'll be looking at Self-Healing using CSS selectors. Using test case Web 01, we will continue to interact with the same web elements, which are the Make Appointment button, Username (with Input UserName as the element), and Password textbox. Let's go ahead and check on their selection methods. For this button, it is set at Xpath, and, like what we did in the last chapter, this locator will be broken due to the addition ''katalon-studio-has-broken-this-locator'' in its ID attribute, and the same goes for the other two. I'll get my trusted Self-Healing on.
All of my locator methods are checked, so this simply means that if Studio couldn't find an alternative element locator using Xpath, then it'll go on with Attributes, CSS Selectors, and Image until a replacement is found. Everything looks good. Click on Apply and Close, and let's run our test case!
We'll now take a closer look at the log viewer, step 3 to be specific. As shown, Xpath was not able to locate an alternative element locator, so it continued searching. Finally, CSS Selector was the one that got the job done. On the right, you can see the full message of ''XPaths were broken - Heal by CSS selector.'' The same went for the 5th step. Xpath was unable to find the username, CSS Selector stepped in and saved the day.
Whereas for Step 6, it didn't repeat the cycle of Self-Healing again, but instead took the working alternative in Step 5 as it used the same Username object. For Step 7, since this broken test object was being interacted for the first time, Self-Healing kickstarts again. Then steps 8, 9, and 10 worked fine. So to end this on a good note, a total of 3 alternative locators were found during our execution, namely in steps 3, 5 and 7. I'll switch over to the Self-Healing Insights and 3 broken locators are listed here, which were self-healed by CSS Selector.
Over in the screenshot column, you can view and see specifically what went wrong. In this case, those are the Make Appointment button, Username, and Password textboxes. Alright, now I'll uncheck the first proposal, and only approve the other two to see what happens. Discard the first one and let's re-run this test case.
And just a reminder on when to discard Self-Healing. If you already know why your element locator has failed and have a specific value to replace it, go ahead and update the object with your value manually without applying Self-Healing suggestions. Let's get back to our test. In this re-run, step 5 and 7 will only apply the CSS Selector method suggested by Self-Healing, not the ones that were initially broken.
Yet, for Step 3, as we'd discarded the Self-Healing's suggestion, Self-Healing stepped in once again. Similar here, but click on the test objects. Password - CSS Selector. Username - CSS Selector. And Make Appointment button - the same old default and broken Xpath. Just like what we've just said.
Click on Self-Healing Insights here again and this time, we'll approve Self-Healing's suggestion for Step 3. Let's re-run this test for the last time. Worked like a charm. Step 3 applied the CSS alternative and Self-Healing no longer had to be involved. Step 8 here will be a bit slower than the rest, since we're using Image as the locator. Alright! All done! Let's end this demo here. See you in the next one!
You've seen how Self-Healing works with XPaths and CSS Selectors, we'll move on to the Image selection method. For this demo, we'll be focusing on this Make Appointment button. And similarly to previous demos, the default locator is Xpath and it is incorrect. And I've also captured a screenshot for the Image selection method. By default, Katalon Studio will display the relative path to the Image, but you can uncheck this box to see the path to where it is stored on your local device.
This time, I'll uncheck every other option and only choose Image as the only alternative selection method for the broken locator, since it is our main focus in this demo. Also, this will speed up the Self-Healing process and the execution as well since it doesn't need to look for other backup methods. Let's get this test running.
The image comparison algorithm in Katalon Studio compares the predefined screenshot of the test object with the current displayed image of the corresponding web element on the active browser, pixel by pixel. That's why you see it's scrolling up and down to capture the whole screen. Alright, it navigates to the next page, indicating the Make Appointment button has been clicked on successfully.
To save our time, I'll stop the test here, and go to the Log Viewer. At step 3 here, it failed to find the element with the default Xpath, then it immediately tried to find it again by Image, following our Self-Healing settings. Moving to the Insights section to review, the broken object has been recovered by Image. However, the locator proposed here is Xpath, not Image.
Well, this is because test objects are found quicker with Xpaths, making the process of Self-Healing faster and reducing the test execution duration. To further explain, when using Image Self-Healing, Katalon Studio has to capture and compare the screenshot with the predefined image, pixel to pixel, to find the test object, like any other automation tools, which normally takes more time.
That's why Studio is set up to propose a new generated Xpath every time an object is healed by Image. And that's also why you should place Image as the lowest priority in the list, to minimize the time needed for Self-Healing and test executions as well.
I'll choose this proposal and click Approve. Let's go ahead and check on our object. Although it is healed by Image, the default locator has been updated with a new working Xpath, just like I've explained. And that's the end of this demo. In the last lesson, we will run an end-to-end test and recap everything about Self-Healing. See you!
For this last lesson, we'll be using Self-Healing on a more complex end-to-end test to verify a purchasing flow on a demo online shopping website and sum up everything we've learned in this course. In these 22 steps, there are 2 broken objects, at steps 9 and 11.
In step 9, For the Image Ninja Thumbnail, the default Xpath locator is non-existing, the Attributes and the CSS Selector are incorrect as well. But for the Image, this is the one that's going to work. And for the button 'Add to cart,' the default locator is also a broken CSS Selector. We'll find out how it's going to be healed after the execution.
Open the Self-Healing settings, you can turn it on or off here, select and prioritize which methods to use, simply by dragging and dropping or using Move up and down buttons. Let's just keep it the way it is, CSS Selector, Attribute, Xpath, and then Image. Or you can select this Self-Healing icon right on the toolbar to quickly enable or disable this feature, and open its settings as well. Alright, our settings are done. Let's run this test!
At the system testing level, you usually would verify end-to-end workflows that users may use the most in the real world. That's why we use this complex test case with 22 steps. But, the more test steps and objects included, the flakier the test will get. A good practice here is to properly break down your long tests into smaller ones. Okay, we got our browser opened up and went to the Katalon demo shopping website. All the next test steps are being executed automatically.
Keep in mind that a test case should be used to verify a particular objective. Meanwhile, UI end-to-end tests should focus on a business flow verification instead of validating different input values. With Self-Healing, Katalon Studio helps you reduce test flakiness by providing backups for a broken or missing object locator when it fails to locate that web element. You can then update the broken objects with new locators with just a few clicks, lessening your effort for test maintenance.
You can see that it's standing here for a while. We're at step 9, and it couldn't find the objects with the default locator and it's searching for the alternatives. See? Scrolling up and down, it's trying to find the test object, the right thumbnail, via image comparison. After successfully clicking on the thumbnail, it has moved to the next screen. And the same process of Self-Healing starts again, it's trying to find the 'Add to cart' button. Once the button is found and clicked on, the rest of the test steps should be executed smoothly.
For automated end-to-end tests, executing them is quite similar to manual testing. But the only difference is in the test automation tool that you're using. With Katalon Studio, it will do all the actions for you, from interacting with elements, waiting for the system response, and carrying out the next actions. And our test case passed! Thanks to Self-Healing. Let's expand the log and have a closer look at the test steps.
So here, at step 9, you can see Xpath, CSS Selector, Attributes, Xpaths again, and finally, Image. It's gone through exactly our predefined priority order. Since the first 3 alternatives are all broken as we mentioned earlier, the object is finally healed with the Image selection method. The same thing goes for the button at step 11. It's gone through all the alternative locators, from CSS Selector to different Xpaths, but none of them works until it is finally healed by Image, like you can see here on the right.
That's it! Congratulations! You've finished our course ''Fix Broken Locators for Web Testing with Self-Healing.'' To recap, you've learned the mechanism of Self-Healing, selecting and prioritizing different selection methods in Katalon Studio, using Xpath, Attributes, CSS Selector, and Image as flexible alternatives for broken locators through our demo, an easy way to update broken objects with new working locators without additional maintenance effort, and how Self-Healing works in complex scenarios, right?
So what's next? Just go to Katalon.com, download, install Studio and apply Self-Healing in your projects now! If this is your first-time activation, you'll get a 30-day trial to explore every single feature in Katalon Studio for Free. Katalon Academy is working on even more courses to help you learn about test automation and immediately put them into practice with Katalon tools. In the meantime, you can watch more of our existing courses by clicking on the Courses button right on the top menu bar. Thank you, and happy learning!
Good , but need a more example for better understanding.
This is wonderful. it's very helpful for beginners of katalon.