Passing values through module boundaries | Ranorex
Help CenterUser GuideRanorex Studio advanced

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

    Sample solution

    The explanations of passing variable values through module boundaries are based on an illustrating example which can be downloaded as a sample solution.

    Training! What do I do?

    Theme: Passing values through module boundaries
    Time: Less than 30 min

    Download sample file

    Installation:

    Unzip the project directory to any folder on your computer
    Start Ranorex Studio and open the solution file PassVar.rxsln

    tipp icon

    Hint

    The sample solution is available for Ranorex versions 8.0 or higher. You need to agree to the automatic solution upgrade for versions 8.2 and higher.

    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

    Passing values through module boundaries – example definition

    InsertFirstName

    • 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

    InsertLastName

    • 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

    AddEntry

    • Recording module representing the click on the Add entry button

    Result(s):

    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

    Test example result with passed variable values

    Solution

    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

    Concept of passing values through module boundaries

    Variable $varFirstName copies the value of the text string in the recording module InsertFirstName

    Variable $varLastName writes its value into the text string in the recording module InsertLastName

    A transfer parameter transferFirst2LastName links 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 InsertFirstName.rxrec.

    Recording module InsertFirstName.rxrec

    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
    The 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 $varFirstName
    The text value is retrieved from the UI-element referenced by the repository item FirstName

    Result(s):

    The text string ‘John’ is collected and copied into the variable $varFirstName.

    Definition of source variable

    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 InsertLastName.rxrec.

    Recording module InsertLastName.rxrec

    Recording module InsertLastName.rxrec

    Important to know:

    Action #1 represents the click into the text field
    The Key sequence action handles the writing of the text value into the text field
    The value to be written is taken from the variable $varLastName
    The text value is written into the UI-element referenced by the repository item LastName

    Result(s):

    The text string ‘John’ is taken from the variable $varLastName and written into the text field referenced by the repository item LastName.

    Definition of target variable

    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

    Creating a transfer parameter

    Select the parent test container (test case, or smart folder) and open the context menu
    Click Data binding…

    Assigning variables to parameter

    Assigning variables to parameter

    Create a transfer parameter with a meaningful name
    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

    Result(s):

    Both recording module variables are now linked together using a parent-container transfer parameter.

    Defined transfer parameter

    Defined transfer parameter

    Source variable $varFirstName of recording module InsertFirstName
    Target variable $varLastName of recording module InsertLastName
    Transfer parameter transferFirst2LastName of parent test case
    Test suite indication that both variables are successfully bound to the transfer parameter

    Result

    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

    Passing values through module boundaries – result