UI Automation - Self Healing Agent

Viewed 1297

I am doing UI automation in Selenium-Java where I am recognising object/element based on XPATH or CSS selector. Due to many unwanted reason - tests are getting failed due to change in XPATH at different environment.

I thought to write a utility script which will identify and auto-generate robust and simple XPaths.

Is there a way - I can make this happen at run time to self heal my existing Selenium-Java automation scripts.

1 Answers

It's not possible to recognize the elements that should get their xpath regenerated without specifying somehow what those elements are.

It's easy for humans to know which one is the "sign up" button, for example, even if its label, style or position changes, since people can use other context clues to guess which button is meant by "the sign up button". Implementing these context clues for a computer would require quite a lot of effort, especially for more obscure type of elements.

I would stick to spending some time and human thought to figure out the most robust locator for each element. (For a sign up button I'd say it's often the value of the href attribute.)

Maybe you could even specify multiple different locators per element. Then implement the search so that the locator that first matches a single element is used and fail only if all specified locators fail. That could decrease the frequency with which a person has to be fixing the tests. Or it could have the opposite effect :)

One more idea: if you can use version control to get the last version that some specific selector still worked, maybe you could try finding the most similar element in the new version and regenerating the xpath for that.

Related