Repository variables | Ranorex
Help CenterUser GuideRanorex Studio advanced

Repository variables

Any UI-element to interact other than a text, or number entry field which is variable can be automated by repository variables. Menu items, list items, or radio buttons are common examples for such UI-elements. The herein introduced concept of repository variable is applied to list items and radio buttons.

In this chapter

    Repository variable identification

    Assume a drop-down list of selection items for a department list. The selection is to be made variable to automate it with a data set.

    Involved action items:

    Action items controlling drop-down list selection

    Action items controlling drop-down list selection

    Action #1 represents the click on the open button of the drop-down list for the department selection
    Action #2 is representing the (constant) selection of the Project Management department item from the list. This selection is to be made variable

    Repository items:

    Department selection list and corresponding repository items

    Department selection list and corresponding repository items

    The Open button of the drop-down list refers to the repository item BtnDepartmentList
    The list item selection refers to the constant repository item ProjectManagement and needs to be replaced by a repository variable to make the selection data-driven

    Repository variable identification:

    The (fixed) selection of list items needs to be replaced with a repository variable.

    Repository variable identification

    Repository variable identification

    Defining repository variables

    Repository items are defined by their name and their location within the GUI. This location is specified by means of the RanoreXPath syntax. Defining a repository variable means replacing parts of the RanoreXPath syntax with a variable. The data-driven variable content then completes the RanoreXPath specification during run-time to make a repository item selection variable.

    Further reading

    If you are not familiar with the concept of RanoreXPath we recommend reading > Ranorex Studio advanced > ⇢ RanoreXPath.

    Making repository item variable...

    Making repository item variable…

    Select the action item being responsible for the corresponding UI-element interaction (in the current example, action #2 is responsible for selecting the item from the department list)
    Open the context menu and click Make repository item variable…

    Repository variable definition

    Repository variable definition

    Identify the correct attribute (in the current example, the text attribute from the ListItem category is selected), open the drop-down list and click As new variable…
    Assign the variable a meaningful name and click OK
    See the repository variable replacing the former constant value of the UI-element attribute
    Click APPLY in the path editor window to end the repository variable specification

    Result(s):

    You can find the result in the repository where the RanoreXPath of the corresponding repository item has been partly replaced by the new repository variable.

    Result of repository variable definition

    Result of repository variable definition

    See the repository item which has been made variable in the action table and in the repository
    Find the modified RanoreXPath specification containing the new repository variable $LstDepartment

    Default variable value

    The initially set (i.e. recorded) value is automatically pre-set as default variable value. In our example, the initially recorded selection of the ‘Project Management’ department is therefore set as default value. Default values can be changed at will.

    Repository variable default value

    Repository variable default value

    Note icon

    Note

    The default value is the value which is applied if the variable is not bound to any data. Therefore, it might be important to choose the default value with care. Defining a proper default value for repository variables is recommended. If no default value is assigned, then highlighting the UI-element from the repository will not work.

    Repository variable management

    Repository variables are managed by clicking the Variables button in the repository toolbar.

    Opening repository variable management

    Opening repository variable management

    Note icon

    Note

    All repository variables of the current repository are displayed in the variable editor.

    Repository variable editor

    Repository variable editor

    List of repository variables with variable name and default value

    Repository variable toolbar

    • Menu to copy & paste a variable to / from the clipboard
    • Option to add a new variable directly
    • Option to remove unused variables (variable cleanup)

    Variable indicator

    • Variable in use: Variable is used, i.e. it is assigned to a repository item
    • Variable not in use: Variable is defined, but not assigned to a repository item

    Applying repository variables to radio buttons

    Making radio buttons variable is a common application of repository variables. This section is to show how to do this.

    Radio button action(s)

    Radio button selection actions

    Radio button selection actions

    Action #1 represents clicking radio button Male
    Action #2 represents clicking radio button Female

    Radio button repository item(s)

    Radio button repository item(s)

    Radio button repository item(s)

    Repository item RdbMale references the male radio button
    Repository item RdbFemale references the female radio button

    Making radio button variable

    Making radio button selection variable

    Making radio button selection variable

    Select the action item being responsible for the corresponding UI-element interaction (in the current example, action #1 is responsible for clicking the male radio button)
    Open the context menu and click Make repository item variable…

    Radio button repository variable definition

    Radio button repository variable definition

    Identify the proper attribute from the list of available attributes (in the current example, the controltext attribute is selected), open the drop-down list and click As new variable…
    Assign the variable a meaningful name and confirm with OK
    See the new repository variable replacing the former constant value of the UI-element attribute

    Repository variable application

    Repository variable application

    Click APPLY in the path editor window to end the repository variable specification

    Result(s):

    You can find the result in the repository where the RanoreXPath of the corresponding repository item has been partly replaced by the new repository variable.

    Result of repository variable making radio button variable

    Result of repository variable making radio button variable

    See the repository item which has been made variable in the action table and in the repository
    Find the modified RanoreXPath specification containing the new repository variable $selGender

    Careful variable selection

    It is necessary to select the variable attribute of repository variables carefully. Selecting the controltext attribute in the current example may be appropriate with respect to the test data items, but might be non-appropriate under different circumstances.

    tipp icon

    Hint

    To make a data-driven testing robust against localization (other languages), it is recommended to use other attributes, such as,ControlName or others.