Passing values across test cases | Ranorex
HomeUser GuideRanorex Studio AdvancedVariables & parametersPassing values across test cases

Passing values across test cases

The purpose of this section is to show how to pass values from one test case into another test case. The concept is similar to passing values through module boundaries and makes use of parameters which are to be defined in parent test containers (smart folder, test case, test suite).

In this chapter

    Sample solution

    The explanations of passing variable values across test cases are based on an illustrating example which can be downloaded as a sample solution.

    Training! What do I do?

    Theme: Passing values across test cases
    Time: Less than 30 min

    Download sample file

    Installation:

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

    Test example definition

    Assume a test where a text string (i.e. a name) inserted into a text field of one application needs to be re-used and inserted into a text field of another application. Source and destination text fields are handled in different test cases within one test suite of Ranorex.

    Test application One

    Test example - part I

    Test example – part I

    The recording module InsertName is responsible for inserting the text string ‘Harry’ into the text field of the first application
    The recording module SubmitName represents the click on the Submit button

    Test application Two

    Test example - part II

    Test example – part II

    The recording module SelectDatabase represents the change to application Two
    The recording module CopyNameFromIntro represents the insertion of the copied name from application One into the text field First name

    Solution

    Each text insertion is represented within a separate test case. Both test cases are contained within the same test suite and have the same parent smart folder PassValuesThroughTestcases. The solution is based on local variables which are responsible for copying and pasting the text value within the corresponding module. As variables are local to their test container, it is necessary to define a parameter which links the variables together and therefore enables data transfer across different test cases.

    Passing values across test cases - solution overview

    Passing values across test cases – solution overview

    Transfer parameter transferValues

    • The parameter is declared in the parent smart folder PassValuesThroughTestcases
    • Therefore, it is accessible to all child test containers, i.e. the two test cases InsertName and InsertFirstName2DB
    • This parameter enables the passing of the value across the test cases

    Source variable $varNameIntro

    • The variable is local to the test case InsertName
    • Its purpose is to copy the text value from the source text field

    Target variable $varNameFromIntro

    • The variable is local to the test case InsertFirstName2DB
    • Its purpose is to paste the text value into the target text field

    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 test case. In the current example, this is the text string of the name in the recording module InsertName.

    Recording module InsertName.rxrec

    Recording module InsertName.rxrec

    Important to know:

    Action #1 represents the click into the text field, where action #2 represents the insertion of ‘Harry’ 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 $varNameIntro
    The text value is retrieved from the UI-element referenced by the repository item EnterYourName

    Result(s):

    The text string ‘Harry’ is collected and copied into the variable $varNameIntro

    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 target text field. In the current example, this is done in the recording module InsertFirstName2DB.rxrec.

    Recording module InsertFirstName2DB.rxrec

    Recording module InsertFirstName2DB.rxrec

    Important to know:

    Action #1 represents the click into the text field First name
    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 $varNameFromIntro
    The text value is written into the UI-element referenced by the repository item FirstName

    Result(s):

    The text string ‘Harry’ is taken from the variable $varNameFromIntro and written into the text field referenced by the repository item FirstName.

    Definition of target variable

    Definition of target variable

    Transfer parameter definition

    As variables are local to their test containers (test case, smart folder) it is necessary to define a transfer parameter which ‘links‘ the variables together and enables the exchange of variable values from one variable to another. This transfer parameter is to be defined in a parent test case or smart folder which contains both test cases.

    Creating a transfer parameter

    Creating a transfer parameter

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

    Transfer parameter declaration

    Create a new transfer parameter and give it a meaningful name
    Note that the parameter cannot be linked to the variables in this parent test container. Leave the module variable binding empty and click OK

    Note icon

    Note

    The variables are private to their test container. Therefore, they are not accessible in a test container upwards the test container structure. But the parameters are accessible downwards a test container structure. Therefore, the linking between parameter and variable needs to done in the test container of the variables.

    Linking of source variable to transfer parameter

    Linking of source variable to transfer parameter

    Linking of source variable to transfer parameter

    Select the test container (test case) hosting the recording module with the source variable
    Open the context menu and click Data binding…
    Binding parameter to source variable

    Binding parameter to source variable

    See the accessibility of the transfer parameter transferValues
    Open the module variable drop-down menu and select the binding of the source variable $varNameIntro

    Result(s):

    The variable $varNameIntro is bound to the transfer parameter transferValues.

    Finished source variable definition

    Finished source variable definition

    Linking of target variable to transfer parameter

    Linking of target variable to transfer parameter

    Linking of target variable to transfer parameter

    Select the test container (test case) hosting the recording module with the target variable
    Open the context menu and click Data binding…
    Binding parameter to target variable

    Binding parameter to target variable

    See the accessibility of the transfer parameter transferValues
    Open the module variable drop-down menu and select the binding of the target variable $varNameFromIntro

    Result(s):

    The variable $varNameFromIntro is bound to the transfer parameter transferValues.

    Finished target variable binding

    Finished target variable binding

    Result

    If you run the prepared sample solution you will see that the name inserted in the name text field of application One is copied into the name text field of application Two.