Using a variable in a variable definition

Ask general questions here.
Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Using a variable in a variable definition

Post by Christoph » Wed Jul 11, 2012 6:58 am

Hi all,

Is it possible (if possible without writing code) to use a variable when defining another variable? (Repository variable, Recording variable and / or Global Parameter) What I'd like to to is to "concatenate" two or three variable into one.

Example:
$progpath = "C:\Program Files"
$applicationPath = "\myApp\bin"
$application = "\myapp.exe"

This is what I want:
$myApplication = $progpath + $applicationPath + $application
So the value of $myApplication would be "c:\Program Files\myApp\bin\myapp.exe"

If it is not possible without writing code, how would I define those variables and how would I access them when defining a repository variable or a recording variable?

Christoph

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

Re: Using a variable in a variable definition

Post by Support Team » Thu Jul 12, 2012 2:01 pm

Hi Christoph,

It is unfortunately not possible to create a new recording variable or repository variable out of other variables without using code, but you can concatenate more variables in the RxPath: "form[@title='...'+$newvariable+'...'+$newvariable1+'...']"

Regards,
Markus
Ranorex Support Team
.
Image

Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Re: Using a variable in a variable definition

Post by Christoph » Fri Jul 13, 2012 6:23 am

Hi Markus,

Thank you for your response. This means I will need to decide, if I define the concatenate variables in code or if I'm better off doing so in an Excel spreadsheet. My main concern is easy maintenance in case a folder path changes sometime in future for one reason or another. I then only want to make one change.

Christoph

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

Re: Using a variable in a variable definition

Post by Support Team » Fri Jul 13, 2012 3:12 pm

Hello Christoph,

You can specify one global parameter for each application. In case that the path of the application changes you only have to modify the global parameter. The other way is to define the paths in a data table and change them there as you described.

Regards,
Bernhard
Ranorex Support Team
.
Image

Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Re: Using a variable in a variable definition

Post by Christoph » Mon Jul 16, 2012 7:02 am

Hi Bernhard,

Thanks for your response. I think I will pursue this approach:
- I will define a global parameter for each variable that I need (more or less)
- in the test case I bound recorder variable to the appropriate global parameter
- I create a code class that contains all definitions that I need
- I create a coded module. This module sets the global parameters dynamically (only once). The values are supplied by the code class that holds all the definitions
- I create a "Testcase" that runs the coded module
- This testcase I run *once* at the very beginning of the test suit

The advantage of this is:
- The global parameters get set at runtime at the very beginning of the test suit.
- all recorder variable will be bound in a test case. I won't get a warning, that I do have unbound variables
- All values are defined at one place, the code class.
- In the code class I can concatenate definitions

Christoph