Variable used in DOM-Element?

Ask general questions here.
dugovic.milan
Posts: 41
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

Variable used in DOM-Element?

Post by dugovic.milan » Mon May 08, 2017 12:27 pm

Hey guys. How do you use variables in DOM Elements on condition that variable's value will be loaded? For instance I have a DOM Element which refers with its web adress (my variable) to a certain testing environment and I'd like to set it within my Excel-File, so that I'll have separate lines/iterations for particular testing environements. Any ideas? Thanks
Ranorex 8.3.0

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Variable used in DOM-Element?

Post by McTurtle » Mon May 08, 2017 4:26 pm

Hello Milan,

You have to do the following:
1. Click on edit at the DOM in your repository
2. Under WEbDocument there should be the attribute 'pageurl'. Next to the URL there is a button to turn it into a variable
makevariable.png
makevariable.png (12.35 KiB) Viewed 468 times
3. Go to your recording view and go to "Variables..." and copy the variable from the repository
copyfromrepo.png
copyfromrepo.png (10.22 KiB) Viewed 468 times
4. Now go to the TestSuite view and an unbound variable should be visible next to the module where you have turned the URL into a variable. Double click on the "Unbound Variable"
unboundvariable.png
unboundvariable.png (6.14 KiB) Viewed 468 times
5. If you are not familiar with how to add a data connector and bind the module variable to it then you can find a detailed description in the Ranorex User Guide: https://www.ranorex.com/support/user-gu ... sting.html

I hope this helps.

Regards,
McTurtle

dugovic.milan
Posts: 41
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

Re: Variable used in DOM-Element?

Post by dugovic.milan » Mon May 22, 2017 2:04 pm

Wow. This helps a lot!
Thanks for detailed instructions McTurtle 8) :lol:
Ranorex 8.3.0

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Variable used in DOM-Element?

Post by Vaughan.Douglas » Mon May 22, 2017 3:43 pm

Depending on the situation I'll use the same process outlined by McTurtle, however more frequently I'll just use regular expressions.

So instead of

Code: Select all

Dom[@pageurl=$variable]
where $variable can be "www.QAEnv.myCo.com" or "www.DevEnv.myCo.com" I'll do this:

Code: Select all

Dom[@pageurl~'www.(Dev|QA)Env.myCo.com']
or without regular expressions.

Code: Select all

Dom[@pageurl='www.DevEnv.myCo.com' OR @pageurl='www.QAEnv.myCo.com'
From a practical prospective this cuts down on the number of variable/parameters I need as the browser usually gets a redirect or five before it actually lands. This means the Page URL for OpenBrowser is going to be different than the actual URL I need in my RxPath for my app. I'll use a global parameter to set the URL for the OpenBrowser method (along with browser type and whatnot) then I'll just use regular expressions to make my DOM RxPath flexible enough to handle the different environments.
Doug Vaughan