Changing of instance number associated to elements

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Changing of instance number associated to elements

Post by Florent » Mon Feb 11, 2013 2:45 pm

Hi Ranorex Support team,

Even it's not the best solution, the best way we found to recognize our application windows to base it on the instance number.

A few weeks ago, i have recorded several scenarios with elements organized as follow : The main window (instance 0) that contains a window A (instance 0), a window B (instance 1) and a window C (instance 2).

The scenarios replay has worked well several days without problems. Today, the replay of the scenario does not work because the order of instance number associated to each windows has changed : The main window (instance 0) that contains a window A (instance 2), a window B (instance 1) and a window C (instance 0).

Is it a bug ? if not, the instance number associated to each element is aleatory ? It there a way to constrain the instance number associated to each element (maybe with a rule to added in a plugin file) ?

Thank you in advance,
Florent

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Changing of instance number associated to elements

Post by Ciege » Mon Feb 11, 2013 11:19 pm

The instance number is automatically generated based on which element gets created first, second, third, etc... Instance number is very likely to break and should not be relied upon as your unique identifier for your elements.

You need to examine your AUT and determine what the best, static, unique identifier is in your AUT. If there are none and the instance ID is it then you should talk with your dev team about properly naming the elements in the AUT.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Changing of instance number associated to elements

Post by Support Team » Tue Feb 12, 2013 10:53 am

Ciege wrote:The instance number is automatically generated based on which element gets created first, second, third, etc...
Well, this is not entirely correct. The instance is automatically computed and differentiates native windows with the same classname, true. However, its value is based on the x/y location of the window (geometry: left before right, top before bottom), not on the order of creation. Otherwise it would be the same as the ordinary index in RanoreXPath (in other words, the order of creation for windows determines the order of siblings in the Ranorex element tree).

Anyway, you are right, the "instance" number is not a very reliable identifier and is only used in RanoreXPaths if there is no other attribute to differentiate native windows. However, for RanoreXPaths of repository folders or if the "instance" is not used to determine the last element in a RanoreXPath, it can be beneficial to remove the "instance". For example:

Code: Select all

/form/container[@instance='5']/button[@controlname='MyButton']
--> /form/container/button[@controlname='MyButton']
If you omit the "instance" in the above example, Ranorex will search all other containers (with instance 1 to 4) as well, but will most probably eventually find the correct button if the button element itself is uniquely identified by its attributes (e.g. with a unique control name).

Currently, Ranorex by default generates RanoreXPaths that try to identify every level in a RanoreXPath uniquely, that's why the "instance" numbers are there sometimes. We are currently evaluating ways to improve the RanoreXPath generation algorithm for cases where a less distinct identification for "container" elements can improve the stability of RanoreXPaths (like in the above example).

Regards,
Alex
Ranorex Team
.
Image

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Changing of instance number associated to elements

Post by Ciege » Tue Feb 12, 2013 4:05 pm

Support Team wrote: Well, this is not entirely correct.
Thanks for clearing up the details. I guess I was a little loose with my understanding of how the internals work... :-)
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Changing of instance number associated to elements

Post by Support Team » Tue Feb 12, 2013 6:26 pm

Ciege wrote:Thanks for clearing up the details. I guess I was a little loose with my understanding of how the internals work... :-)
You are welcome! Your explanations were almost correct - actually, the instance number worked exactly as you explained in Ranorex 1.X :D

Regards,
Alex
Ranorex Team
.
Image

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Changing of instance number associated to elements

Post by Florent » Wed Feb 13, 2013 6:15 pm

Many thanks for all those details Ciege and Support team

I have the possibility to choose another property to identify the elements but the number of instance simplified the work. Indeed, in the past, i chose a unique identifier for each window : the window title. It worked well but there is the current date and others variables text in my windows titles. So after each recording, i have to remove the variable part from the title in the RanoreXPaths recorded in the repository. It's quite boring. Otherwise, a scenario recorded today does not work tomorrow.
Is there a solution, a Ranorex plugin, to do this repetitive work automatically ?
A rule to add in the "Editing Path weights" form ?

On the other hand, when i base the recognition on the instance number, i have 1 repository item for the same button ( for example, a "validate" button) in 2 windows with differents titles but the same instance number. So my repository did not grew too much.

If it's not possible, i will come back to the old way of work...

see you soon

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Changing of instance number associated to elements

Post by Ciege » Wed Feb 13, 2013 6:21 pm

You can easily "ignore" the date in the window titles by using a RegEx in your XPath.
Have a read here: http://www.ranorex.com/support/user-gui ... html#c3294
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Changing of instance number associated to elements

Post by Florent » Thu Feb 14, 2013 10:01 am

Thank you Ciege
with all those elements, i'm in a good way to find a solution
i'll tell you
see you soon