Welcome to the new Ranorex Support Portal

Define test and variables

In this chapter, we’ll first define the steps of the data-driven test. Then, we’ll define the required variables for this scenario. You’ll also find out how to manage variables in Ranorex Studio.

Variables are one of the key parts of data-driven testing. They are the placeholders for values you want to feed your test, either from data sources or parameters. In Ranorex Studio, we differentiate between three types of variables: Action variables, their subtype validation variables, and repository variables.

In this chapter

Note Icon

Screencast

The screencast “Defining variables” walks you through the information found in this chapter.:

Watch the screencast now

Test definition


As usual, we’ll use the Ranorex Studio Demo Application for our example. It has a database function that we’ll test. Testing a database is a common real-world application of a data-driven test.

The test will contain the following steps:

  1. Start the Demo App.

  2. Click the Test database tab.

  1. Add an entry to the database.

  1. Repeat until there are 8 entries in the database…

  2. …and after each entry, validate that the Number of entries updates correctly.

  1. Close the Demo App.

Sample solution and prepared modules

The ⇢ sample solution already contains all the modules with the necessary actions for the steps above. They are organized in a simple test suite. This will serve as our starting point for the next step: replacing constant values in several modules with variables.

  1. Module browser with recording modules structured in folders

  2. Test suite with a ready-to-run database test scenario

Define action variables


Action variables replace a constant value in a component or property of an action, e.g. the specific text string in a Key sequence action. Action variables are limited to the recording module they’re defined in.

First, we’ll replace the constant text values in the respective actions for entering the first name, last name, and age of a person in the Demo App database.

Note Icon

Note

In Ranorex Studio, variable names have the pattern $<variablename>, where <variable name> cannot start with a number or contain any special characters, except for underscores.

To replace a constant value with a variable:

  1. Open the drop-down list for the constant value you want to change and click As new variable…

  2. Name the variable so you can easily identify what value it is a placeholder for and click OK.

  3. The variable appears in the action table in green, replacing the constant value.

  1. Repeat the above process for the last name (InsertName module) and the age (InsertAge module).

The final result should look like this:

  1. Variable $txtFirstName replacing the constant value ‘John’ for the first name

  2. Variable $txtLastName replacing the constant value ‘Public’ for the last name

  3. Variable $intAge replacing the constant value ’48’ for age

Note Icon

Note

Action variables can only be used in the recording module you defined them in.

Define repository variables


Aside from making action values variable, data-driven testing often involves creating repository variables. Repository variables replace a certain part of an item’s RanoreXPath, the defining attribute, with a variable. You can make any repository item variable this way. Repository variables are available in the repository they were defined in and all modules that reference this repository.

For our example, we’ll make a list selection and radio buttons variable. These are repository items where it often makes sense to make them variable because they are usually part of a selection process with multiple options.

Download

Reference


For more information on RanoreXPath, go to

Ranorex Studio advanced >  ⇢ RanoreXPath

Make a list selection variable

Here, we’ll make the repository item for the Department list selection variable. In the module SelectDepartment of the sample solution, the Click action is linked to a constant repository item that points to the Project Management entry in the list. In the item’s RanoreXPath, the attribute @text=’Project Management’ is responsible for this.

We will now replace the constant attribute value Project Management with the variable $lstDepartment so the Click action is performed on whatever list entry our future data source specifies.

Note Icon

Note

When we create our data source later, we will need to make sure the entries for the department selection are exactly the same as in the list, or else Ranorex Studio won’t be able to identify the UI elements. For example, there is no entry IT, so a repository item with the resulting attribute @text=’IT’ wouldn’t point to anything.

To define the variable:

  1. Right-click the second Click action and choose Make repository item variable…

  1. Ranorex Spy opens with the constant value of the text attribute already highlighted. Click the variable symbol next to it.

  2. Name the variable so you can easily identify what repository item it refers to and click OK.

  3. In the yellow bar, click Apply.

  1. In the repository, you can now see the variable in the item’s RanoreXPath.

  1. Repository variable $lstDepartment replaces the constant value for department selection.

Make radio buttons variable

Here, we’ll make the repository item for the Gender selection variable. In the module SelectGender of the sample solution, the Click action is linked to a constant repository item that points to the radio button for Male. In the item’s RanoreXPath, the attribute @controlname=’rdbMale’ is responsible for this.

We will now replace the constant attribute value in the RanoreXPath of this repository item with a variable ($selGender) so the Click action is performed on whatever Gender radio button our future data source specifies.

Note Icon

Note

When we create our data source later, we will need to make sure the entries for the gender selection are exactly the same as the respective @controlname attributes of the two radio buttons, i.e. rdbMale and rdbFemale, or else Ranorex Studio won’t be able to identify the UI elements. A data source with just Male and Female would not work, because the repository item with the resulting attribute @controlname=’Male’ wouldn’t point to anything.

Note Icon

Hint

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

To define the variable:

  1. Right-click the Click action and choose Make repository item variable…

  1. Ranorex Spy opens with the constant value of the text attribute already highlighted. Click the variable symbol next to it.

  2. Name the variable so you can easily identify the repository item it refers to and click OK.

  1. In the repository, you can now see the variable in the item’s RanoreXPath.

  1. Repository item representing the Gender radio button selection with variable $selGender

Note Icon

Note

Repository variables can be used in the repository you defined them in and all recording modules that use this repository.

Define validation variable


Our example test includes a step that validates whether the database counter updates correctly as entries are added. For this validation to work, we need to make it variable.

So, we’ll replace the constant Match value of the validation action in the ValidateEntries module with a variable.

Note Icon

Note

In principle, validation variables are the same as action variables. However, as the Validation action is more complex than most others, we treat their variables separately and therefore also explain the process separately.

To define the variable:

  1. Open the drop-down list for the Match value and click As new variable…

  2. Name the variable so you can easily identify the value it is a placeholder for and click OK.

  3. The variable appears in the action table in green, replacing the constant value.

Default values


The default value of a variable is the value that’s used when no data source is available. This is the case when running a recording module from the recording module view, for example. Therefore, you should always make sure to define a meaningful default value.

Note Icon

Note

When you replace a constant value with a variable, the original constant value is automatically used as the default value.

View and manage variables


You can view the status of variables and manage them in different places: the data binding pad gives you a detailed overview of the status of all variables in a recording module, while the VARIABLES… dialog allows you to add variables and to edit them.

Data binding pad

When opened in the recording module view, the data binding pad shows the status of action, repository, or code variables in this recording module and their default values. The data binding pad reflects the icons and status designations from the VARIABLES… dialog. These are explained in the next topic below.

1

While in the recording module view, click the View data-binding button in the toolbar.

2

To display action or repository variables, their status (In use/In use from repository/In use in code/Not in use) and their default values, click anywhere in…

a

the action table or

b

the repository.

  1. If the recording module contains variables that are only used in code, then these initially appear under Not in use. The button Identify code variables identifies them and causes them to be displayed under In use in code.

VARIABLES… dialog

This dialog shows you variable status and also lets you add and edit variables.

To open the dialog for managing variables:

  1. For action variables, open the recording where they are defined and click VARIABLES….

b

For repository variables, click Variables… in the repository view.

The variable management dialog will open:

  1. Variable status, Name, and corresponding Default value

  2. Variable editor toolbar

  • Options to copy/paste a variable to/from the clipboard.
  • Option to add a new variable directly.
  • Option to remove unused variables (variable cleanup).
  • (Action variable dialog only) Option to copy a repository variable to the current recording module, where it becomes an action variable.
  1. Variable status legend

  • Variable in use: Variable is used, i.e. it is assigned to an action. Does not indicate whether the variable is bound/unbound to a data source.
  • (Action variable dialog only) Variable in use from repository: Same as previous, but for repository variables that are in use in the action table through a linked repository item.
  • Variable not in use: Variable is defined, but not assigned to an action item. Does not indicate whether the variable is bound/unbound to a data source.

Overview of defined variables


We’ve now defined all the variables we need for our data-driven test. When you switch to the test suite view, you can now see the number of variables defined per module. Note they are still unbound, i.e. they have not been assigned a data source.

In the next chapter, we’ll define this data source and assign it to our test case. We’ll also discuss the options for managing data sources.

  1. The test suite view displays the defined, but currently unbound variables

USERS LOVE US

SUBSCRIBE TO OUR NEWSLETTER

Get the latest test automation information right in your mailbox.

FOLLOW US

© 2024 Ranorex GmbH. All Rights Reserved