How to bind global param to all test cases

Ranorex Spy, Recorder, and Studio.
pksy
Posts: 10
Joined: Fri Dec 16, 2011 7:06 pm

How to bind global param to all test cases

Post by pksy » Fri Dec 16, 2011 9:35 pm

Hi, I've gone through the tutorial but I'm still fairly new to Ranorex so please bear with me.

My test suite contains test cases that will always refer to the same client name. For ex. in TC1, I select the client from a dropdown while in TC2, I enter the client name in a text box. I've set the client name to be a repo variable (repo.clientName) to be used for TC1 and TC2. I have a global parameter where I set the actual client name and from what I understand, I would need to bind this with the clientName variable for each test case. Is there a way of binding the global parameter to the repo.clientName for each test cases using a code module and have this code module run at the beginning of each TC? Basically, I want to avoid having to go to every TC and bind the global parameter.

I tried the following code but the client name being used is still the default value set in the repository.

private Controller.ControllerRepository repo = Controller.ControllerRepository.Instance;
repo.clientName = "Test Company";

Thanks
Patrick

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

Re: How to bind global param to all test cases

Post by Support Team » Mon Dec 19, 2011 11:39 am

Hi,

You can create a code module which you drag&drop at the beginning of all your test cases. In the run method of your code module you can set the repository variable to your global parameter with the following code line:

Code: Select all

repo.myRepositoryVaribale = TestSuite.Current.Parameters["yourGlobalParameter"];
Note that you can set the value of a global parameter from the outside using arguments for the exe file.
Regards,
Martin
Ranorex Support Team
.
Image

pksy
Posts: 10
Joined: Fri Dec 16, 2011 7:06 pm

Re: How to bind global param to all test cases

Post by pksy » Mon Dec 19, 2011 8:28 pm

Hi Martin, I appreciate your response.

How would this work for variables that are define for each recording? For example, I have a recording where I enter the candidate first name in a text field. I made the name as a variable (candidateName) and when I click on the "Variables" toolbar menu in the recording, it shows up as a variable. But when I go to the repository and click on the "Variables" toolbar menu, the variable candidateName isn't listed.

Is there a way to set the values of those variables as well using the solution you provided?

Or is there a way to create a variable in the repository that I can use for the candidate name?

Or am I doing something wrong complete?

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

Re: How to bind global param to all test cases

Post by Support Team » Tue Dec 20, 2011 8:02 am

Hi,

Basically, variables defined within a CodeModule or RecordingModule should help you parameterize and reuse your modules.
Variables in the repository are different, define them to identify elements on your UI dynamically, e.g. /form/button[@ControlName=$myVariable]. It is also possible to use them in the way you do, providing data to modules.

I'm not sure what exactly you are looking for, but I tried the find out more about the behavior of the parameters and variables, attached to this post, there is the result of my trying... it's a piece of bad code, but it should give you an idea how to work with variables and parameters.

Note that you can read the value of repository item (eg input field) and write it in a variable too - you are in a .NET environment, therefore, everything is possible ;)

Ranorex Documentation about code modules
Ranorex Code Examles

Regards,
Martin
Ranorex Support Team
Attachments
GlobalBind.rar
(12.3 KiB) Downloaded 225 times
.
Image