Passing values through module boundaries
Values and variables are local to their modules. This usually means that a variable defined within one module cannot be shared among other modules. Sometimes it is useful, or necessary to share the content of values and variables among other modules. Here is how to do this!
In this chapter
The explanations of passing variable values through module boundaries are based on an illustrating example which can be downloaded as a sample solution.
- Unzip the project directory to any folder on your computer
- Start Ranorex Studio and open the solution file
Test example definition
Assume a test case where one text string (i.e. a name) is to be inserted into two separate text fields of a database form. Each text insertion is realized by a separate recording module. Instead of inserting the text string twice, the concept of passing a value from one module to the other module is applied.
Passing values through module boundaries – example definition
- Recording module representing the first text string insertion into the text field First Name
- The value of this text string is also to be copied to the second text field
- In the current example, the text string is ‘John‘
- Recording module representing the second text string insertion into the text field Last Name
- The value of this text string shall be the same as the one from the first text string
- Recording module representing the click on the Add entry button
The result is, that both text fields contain the same text string – the second copied from the first one.
Test example result with passed variable values
The solution is based on the concept of variables. Variables in each recording module ‘carry‘ the value from one text field into the other text field. And because variables are local to their (recording) modules, a transfer parameter of the parent test container is needed to link the variables together. Let’s have a look at the concept.
Concept of passing values through module boundaries
$varFirstNamecopies the value of the text string in the recording module
$varLastNamewrites its value into the text string in the recording module
A transfer parameter
transferFirst2LastNamelinks both variables together and enables passing a value from one recording module to the other
Source variable definition
In a first step, the source variable is to be defined. This is the variable which copies the source text string for handling it over to the target (recording) module. In the current example, this is the text string of the first name in the recording module
Recording module InsertFirstName.rxrec
Important to know:
Action #1 represents the click into the text field, where action #2 represents the insertion of ‘John’ as the text value
Get value action collects the text value from the text field
The value to be handled is a text value
The text value is locally stored in the variable
The text value is retrieved from the UI-element referenced by the repository item
The text string ‘John’ is collected and copied into the
Definition of source variable
Target variable definition
In a second step, the target variable is to be defined. The content of this variable is written into the second text field. In the current example, this is done in the recording module
Recording module InsertLastName.rxrec
Important to know:
Action #1 represents the click into the text field
Key sequence action handles the writing of the text value into the text field
The value to be written is taken from the variable
The text value is written into the UI-element referenced by the repository item
The text string ‘John’ is taken from the
Definition of target variable
Transfer parameter definition
As variables are local to their modules it is necessary to define a transfer parameter which ‘links‘ the two variables together and enables the exchange of variable values from one variable to another. This transfer parameter is to be defined in the parent test case or smart folder which contains both recording modules.
Creating a transfer parameter
Click Data binding…
Assigning variables to parameter
Open the drop-down list of the module variables and check both variables to link them to the transfer parameter
Click OK to end the parameter definition
Both recording module variables are now linked together using a parent-container transfer parameter.
Defined transfer parameter
$varFirstNameof recording module
$varLastNameof recording module
transferFirst2LastNameof parent test case
Test suite indication that both variables are successfully bound to the transfer parameter
If you run the prepared sample solution you will find the below-displayed result. The text string of the text field ‘First name‘ is automatically inserted into the text field ‘Last name‘, as if it was done by user interaction. The transfer of the value is done by means of variables and a parent class parameter.
Run the test case
PassValuesThroughModules and you will see the below-displayed result:
Passing values through module boundaries – result