Self Healing UI Test Automation
Tags: testautomation, ai, testing, testdev
Published: 2021-05-02 19:30:17

## Getting Started
Simulating human-machine interactions using UI Automation tools has been one of the best productivity improvements in validating application quality in a scalable and performant manner. 

However the possibility of dynamic selector(s) has always caused flaky tests and has been the cause for major reservations for many.

Although experts know ways to robustly develop/fix automated UI tests, they are quite ill perceived by many others and are thereby avoided.

We are going to checkout an easy way handle those dynamic selectors using [TestProject](https://testproject.io).

TestProject provides us with a self healing test automation platform which renews failing locator using AI to identify new locators.

*Here is how it works...*

*For the sake of this tutorial I will be focusing on the test creation part.  
For the installation guide [check here](https://docs.testproject.io/getting-started/installation-and-setup).*

## Test Setup
1. Create a new test by clicking on <button style="background-color:#00a5da; color:white;border-radius:3px">New Test</button> and setting any desired *name*.
2. For this tutorial select **Web** as the **test type**. And click Next.
{% details Details (Step: 1 & 2) %} ![New Test][NewTest] {% enddetails %}
3. Now on the Select web application dialog, click on the **Web applications** dropdown and select **Add a new application for testing**.  
*I will be using the [the internet heroku app][theinternetherokuapp] for this tutorial.*
To follow along set following parameters:
```
Name: internet heroku app
URL: https://the-internet.herokuapp.com
```
{% details Details %} ![New Application][NewApplication] {% enddetails %}
4. Since the AI based Self Healing functionality is available in the Web interface of TestProject, select to store the test on the cloud.
5. For simplicity's sake I have used the recording feature to get you familiar with the UI of the test editor. This is the same UI that will assist us later to stabilize identification of the dynamic elements.
{% details Details %} ![Get Started][GetStarted] {% enddetails %}

## Test Steps  
   1. Launch [the internet heroku app][theinternetherokuapp].
   2. Click on Dynamic Content link.{% details Details %} ![TestSteps][TestSteps] {% enddetails %}
   3. Select the first paragraph on the page for Dynamic Content and check if it is correctly recognized by highlighting it in the UI.{% details Details %} ![SelectFirstPara][SelectFirstPara] {% enddetails %}
   4. Refresh page and try to highlight the same element again. This time it will fail since initially the achor was the text content itself which has now changed.{% details Details %} ![refreshpage][refreshpage] {% enddetails %}
   Now things get interesting. We have arrived at the stage where the dynamic element is not recognized by the automation. Now think... how can we fix this...
   Think of all the ways in which you can fix this test to make it robust. Once you're done, read the next step.  
   5. Fixing the dynamic locator failure is as simple as re-running the test or specific step. TestProject will run AI analysis and finds a replacement locator. To avoid AI bias, you get approval over the selections.{% details Details %} ![updatelocator][updatelocator] {% enddetails %}
   6. Once confirmed go back to the test and re-run it as many times as you like and the dynamic content is handled just fine.

Using the power of AI to automatedly fix dynamic locators could never have been any easier. Although many coders are skeptical about record-playback style tools, I urge all to give it a shot. It just might be worth your time.

## For more detailed illustration, refer following video:
{% youtube Pila6IZ3J6U %}

<!-- links -->

[theinternetherokuapp]: https://the-internet.herokuapp.com "the-internet-heroku-app"

[NewTest]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nit4xuyckvglhuz8tkg5.gif "New Test"

[NewApplication]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k3iesnkmn9opl3l8192a.gif "New Application"

[GetStarted]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7i38025ofvqqjvwblr4.gif "Get Started"

[TestSteps]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c56n6hyyo0696ndrp1j8.gif "Test Steps"

[SelectFirstPara]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n45ylexvjepp88jluqp9.gif "Select First Paragraph"

[refreshpage]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tydmjtrvrn5ajz1o2ba2.gif "Select First Paragraph"

[updatelocator]: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m57jspn0akgbohod0ero.gif "Update Locator"