Adressing same object in different browser instances

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
steve20
Posts: 6
Joined: Wed Jun 04, 2014 9:13 am

Adressing same object in different browser instances

Post by steve20 » Mon Aug 18, 2014 3:26 pm

Hey everybody,

currently i'm automating some test cases with two browsers being open in parallel, one is IE and the other one FF.
In the test case i have to click on an object in one browser (FF) first then switch to the other browser (IE) and click on the same object. An error message will occur in the second browser (IE) because its not possible to be in the same state in two browsers.
My Problem is that Ranorex always jumps to the first browser (FF) when i want to click the element in the second browser (IE) even if i added the "Focus"-Action in my Recording module.
Can anyone help me diffenrentiate the same element in two different browsers?
btw: i'm a beginner in Ranorex.

Ciao

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Adressing same object in different browser instances

Post by krstcs » Mon Aug 18, 2014 4:16 pm

Welcome Steve!

First off, I would recommend that you learn about working with RanoreXPath (RXPath), Ranorex's version of the XPath specification, which it uses to identify elements of the system-under-test's GUI. If you haven't read through the Ranorex User Guide, it will help a lot.
http://www.ranorex.com/support/user-guide-20.html



Second, the best way to do this is to variablize the RXPath of the root DOM object in the repository.

For instance, the DOM's path normally might be:
"/dom[@domain='www.mydomain.com']"

In order to make it specific to a certain browser (say Mozilla Firefox), you could change the XPath to this:
"/dom[@domain='www.mydomain.com' and @browser~'Firefox']"
Notice the "~", which is the symbol for regex in RXPath. Ranorex will look for a /dom object that has the domain 'www.mydomain.com' and has a browser attribute that matches the regex 'Firefox'.

Now, if you want to make it work with ANY of the 4 supported browsers (IE, FF, Chrome, Safari), you can make the RXPath look like this:
"/dom[@domain='www.mydomain.com' and @broswer~$Browser]"

The "$Browser" part is a variable, and Ranorex will add it to the list of variables. You can then bind that variable in the Test Suite to a data source that contains a list of all of the browsers you want to test on.



A couple of things I would suggest since you are new to Ranorex:

1. Keep your Recording Modules as small as absolutely possible and name them appropriately for what they do. For instance, if you need to click the OK button on a dialog, name the module "Click_OKButton" and only put the one mouse-click action for the OKButton repo object in the action table. If you need to enter text in a text box (UserName for example), you can name the module "Enter_UserName" and have it only do the things required to actually enter the username in the field. The actions might look like this:

Code: Select all

// 'UserName' field in repo and '$UserName' variable in recording module
Mouse -> Click -> Left -> Center -> UserName
Keyboard -> Shortcut -> 'Ctrl-A' -> UserName  (This makes sure any current value is overwritten.)
Keyboard -> Key Sequence -> $UserName -> UserName
Validate -> AttributeEquals -> InnerText -> $UserName -> UserName (This validates that the text was entered correctly.)
This will allow you to just drag them into the Suite/Case and know they will do just what they say.

2. Be consistent with your naming scheme. This will make it easier to manipulate tests and bind variables in the long run, and everyone will be able to understand what is going on more easily. For example, as you saw above, I named my field and the variable that is entered in the field the same thing (UserName). And the module is name as <Action>_<Field/Variable>, so you know exactly what the module does, what element it does it to, and what variable is required. For more complex actions, you might name it like this: <Action>_<Field>_for_<Variable>_and_<Variable>. Don't worry about long names, we want to make them readable so people who can't write code can still string together tests.

3. Use a versioning system like SVN or Git. You are developing software so start off right.

There is more, but I'll leave it there for now. :D

Have fun, and ask questions!
Shortcuts usually aren't...

steve20
Posts: 6
Joined: Wed Jun 04, 2014 9:13 am

Re: Adressing same object in different browser instances

Post by steve20 » Tue Aug 19, 2014 9:44 am

Hey krstcs,

thank you very much for your hints. I tried it and now it works properly.
Thank you, too, for your additional advices using Ranorex.

I'll ask or search for the answer first if any questions come up!

Ciao