p2018
p2018

Reputation: 125

Self Healing of Selectors in UI Automation

I am doing UI automation in JS 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 am looking for idea or an approach - where my automation scripts self heal to recognise the changed XPATH/CSS selector and updates or run with changed selector.

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

Upvotes: 0

Views: 1249

Answers (1)

C. Peck
C. Peck

Reputation: 3711

First of all, automated UI tests inherently require maintenance for page changes that cause test failures. Most often these failures are a result of changes that make existing element selectors no longer work as desired. I don’t think any solution is available to change these selectors programmatically; you’d probably have to write this yourself.

In my view the best way to approach this is

  1. Adopt a locator strategy that uniquely identifies your elements while relying on as little of the DOM as possible. For me the ideal would be to have a unique Id or some other unique tag. Personally I very rarely use Xpath because it is most likely to depend on other elements, increasing the likelihood and frequency of tests needing maintenance, and it is the slowest way to locate an element.

  2. QA should be involved from the very beginning of the development process so that they can, as early as possible, identify any changes that need to be made to automated tests to accommodate upcoming features. Also, QA can collaborate with developers to establish the most “testable” product possible, usually including requests for HTML tags to help uniquely identify elements. Ideally the changes required to existing tests can be made as development occurs so that broken selectors do not delay the release cycle.

  3. Finally I think we just have to accept a certain level of flakiness and required maintenance for UI automation. Google’s target for “flaky” UI tests is 1% or less. Selenium is a great browser automation tool, but it takes a lot of planning and strategy to write reliable, maintainable, and robust UI tests. And I think considering what changes might break which selectors is essential when designing tests and locator strategies. A tool that automatically does this would be awesome, and I believe there are teams working on creating a way to do so with artificial intelligence, but nothing is publicly available yet.

Upvotes: 3

Related Questions