Increase level of abstraction from UI Elements

Best practices, code snippets for common functionality, examples, and guidelines.
gvrachliotis
Posts: 8
Joined: Wed Aug 31, 2016 8:29 am

Increase level of abstraction from UI Elements

Post by gvrachliotis » Tue Mar 07, 2017 9:32 am

Hi all,
one of the most common issues I have in ranorex projects is projects not working after a few new software releases, due to changes in UI elemets, e.g. changes in html attributes used to track elements etc. What would be the best practices for developing ranorex projects in order to increase the level of abstraction from UI elements and what would be some good practices for developers to embed in their code in order to help maintain automation testing for the long run? Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Increase level of abstraction from UI Elements

Post by odklizec » Tue Mar 07, 2017 1:57 pm

Hi,

In my opinion, there could greatly help two things...
1) stop using element indexes (and any hardcoded things) in your xpaths
2) ask developers to add unique (and reasonably named) IDs to critical GUI elements

As for 1) If Ranorex recording/tracking cannot find reasonable element IDs, it starts using indexes. However, you can almost always improve your xpath by eliminating element indexes and replacing them with relative xpath attributes or by referencing to another (neighboring) elements. Yes, manual work is required, but honestly, you should examine (if not improve) recorded xpaths after each recording/tracking session. Recording is a great help, but lacks the human intelligence and intuition ;) So you should not rely on it too much!

As for 2) this is hard one. Unique IDs are best for quick identification of elements. Sadly, many apps lacks them and it's hard to persuade developers to not forgot about them, when adding new GUI elements ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

qwertzu
Posts: 178
Joined: Wed Jan 25, 2017 11:08 am

Re: Increase level of abstraction from UI Elements

Post by qwertzu » Tue Mar 07, 2017 2:15 pm

Hi gvrachliotis,

The best practice would be that your developers use attributes and values that will not change in later versions. In this case you will not have to change your paths in Ranorex to find elements.

If this can not be accomplished, you can also try to make parts of your RanoreXPaths variable.

Example:

Path to the Logo on the Ranorex Website:

/dom[@caption~'^Test\ Automation\ for\ GUI\ T']//div[#'main-nav']//a[@href='http://www.ranorex.com/']/img[@alt='Ranorex test automation']

If you know, that in the future i.e. the Website-URL will change, simply create a variable by clicking on the "variables" button in your repository and use it in the RanoreXPath.

The path would look like this:
/dom[@caption~'^Test\ Automation\ for\ GUI\ T']//div[#'main-nav']//a[$someVariable]/img[@alt='Ranorex test automation']

You can fill this variable i.e. within user code and as soon as the attribute and/or the value of the URL need to be changed, you will simply have to change the variables value.
This will make changes easier than changing each RanoreXPath that uses this URL.

I hope this helps.

gvrachliotis
Posts: 8
Joined: Wed Aug 31, 2016 8:29 am

Re: Increase level of abstraction from UI Elements

Post by gvrachliotis » Tue Mar 07, 2017 3:45 pm

Thanks for your replies!

Typically, my workflow is record a test script and then try to edit/clear xpaths in repository elements, by tracking elements using a unique or a combination of unique attributes or by parents or siblings. But as long as I have experienced only unique attributes that do not change in new releases work ok for our automation projects.

Apart from unique IDs or other unique attributes, like NAME in input tags, are there any other guides or good practices that we could give to our devs, especially in mobile apps?

qwertzu
Posts: 178
Joined: Wed Jan 25, 2017 11:08 am

Re: Increase level of abstraction from UI Elements

Post by qwertzu » Wed Mar 08, 2017 1:32 pm

Hi,

As already mentioned, the best thing your developers can do is using unique attributes to identify elements that won't change in later versions. Then you will not have to change your paths in the future.
This is true for all applications.