First, define the steps of the data-driven test. Then, define the variables required for this scenario and learn where to view and manage variables in Ranorex Studio.
Variables are placeholders for values you want to feed your test, either from data sources or parameters. In Ranorex Studio, there are three variable types used in this workflow: action variables, validation variables (a subtype of action variables), and repository variables.
Test definition
For this example, use the Ranorex Studio Demo Application. It contains a database feature, an example that maps well to data-driven testing because the same workflow repeats while input values change.
The test contains the following steps:
- Start the Demo App and click the Test database tab.
- Add an entry to the database by clicking Add entry.
- Repeat until there are 8 entries in the database.
- After each entry, validate that the Number of entries updates correctly.
- Close the Demo App.
Sample solution and prepared modules
The sample solution already includes the modules and actions for the steps above in a ready-to-run test suite. You’ll use it as the starting point for the next step: replacing constant values with variables.
- Module browser with recording modules structured in folders.
- Test suite with a ready-to-run database test scenario.
Define action variables
Action variables replace a constant value in an action (for example, a text string in a Key sequence action). Action variables are limited to the recording module where you define them.
In this example, you’ll replace the constant values for first name, last name, and age with action variables.
To replace a constant value with a variable:
- Open the drop-down list for the constant value you want to change and click As new variable…
- Name the variable so you can easily identify what value it is a placeholder for and click OK.
- The variable appears in the action table in green, replacing the constant value.
- Repeat the above process for the last name (InsertName module) and the age (InsertAge module).
The final result should look like this:
- Variable
$txtFirstNamereplacing the constant value ‘John’ for the first name. - Variable
$txtLastNamereplacing the constant value ‘Public’ for the last name. - Variable
$intAgereplacing the constant value ’48’ for age.
Define repository variables
Repository variables replace part of a repository item’s RanoreXPath (the attribute value) with a variable. Repository variables are available in the repository where you define them and in all modules that reference that repository.
In this example, you’ll make two common selection targets variables:
A list selection (Department)
Radio buttons (Gender)
Make a list selection variable
Here, let's 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.
Let's 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.
To define the variable:
- Right-click the second Click action and choose Make repository item variable…
Ranorex Spy opens with the constant value of the text attribute already highlighted. Click the variable symbol next to it. - Name the variable so you can easily identify what repository item it refers to and click OK. Additionally, click Apply.
- In the repository, you can now see the variable in the item’s RanoreXPath.
- Repository variable
$lstDepartmentreplaces the constant value for department selection.
- Repository variable
Make radio buttons variable
Here, let's 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.
Let's 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.
To define the variable:
- Right-click the Click action and choose Make repository item variable…
- Ranorex Spy opens with the constant value of the text attribute already highlighted. Click the variable symbol next to it.
- Name the variable so you can easily identify the repository item it refers to and click OK.
- Click Apply.
- In the repository, you can now see the variable in the item’s RanoreXPath.
- Repository item representing the Gender radio button selection with a variable
$selGender
- Repository item representing the Gender radio button selection with a variable
Define validation variable
The test validates that the database counter updates correctly after each entry. To make this validation work across different data rows, replace the constant Match value with a variable.
So, we’ll replace the constant Match value of the validation action in the ValidateEntries module with a variable.
To define the variable:
- Open the drop-down list for the Match value and click As new variable…
- Name the variable and click OK.
- The variable replaces the constant value in the action table (shown in green).
Default values
The default value of a variable is the value that is 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.
View and manage variables
You can view variable status and manage variables in two places:
Data binding pad: Quick overview of variable status and default values for the current recording module.
VARIABLES… dialog: Add/edit variables, remove unused variables, copy/paste, and other management tasks.
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.
- While in the recording module view, click View data-binding in the toolbar.
- 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…
- The action table
- The repository
- 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.
- Open the dialog for managing variables.
- For action variables, open the recording where they are defined and click VARIABLES….
- For repository variables, click Variables… in the repository view.
The variable management dialog opens:
- Variable status, Name, and corresponding Default value
-
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. -
Variable status legend
Variable in use: A variable is used, for example, 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
You have now defined all variables needed for this data-driven test. In the test suite view, you can see how many variables each module contains. At this stage, the variables are still unbound (not yet assigned to a data source).
- The test suite view displays the defined, but currently unbound variables.
Next step: In the next article, you’ll define a data source, assign it to your test case, and review your data source management options.