Now that you defined our variables and assigned the data source to the test case, you are ready to connect them. This is called data binding, which is the topic of this chapter.
Initial situation
The image below shows the initial situation with the data source assigned to the test case and the defined, but unbound variables next to the recording modules.
-
Data source myCSVData with 8 data rows assigned to a test case.
-
6 unbound variables in 5 recording modules.
Access data binding
1. Use one of the following options:
a. Right-click a test container and click Data binding…
b. Double-click an unbound variable.
The data binding dialog
The data binding dialog opens with the following items:
-
Data binding tab in the properties window of the test container
-
List of available data columns from the assigned data source
-
Multiple drop-down menus containing the defined variables available for binding
-
Auto-bind function explained at the end of this chapter
-
Unbinds all variables from their data columns
Bind data to variables
Binding data to variables means specifying one variable per column.
For the column FirstName:
-
Open the drop-down list of variables next to the data column.
-
Check the variable to which the data is bound. In this case: InsertName.txtFirstName
Variable names in the data binding dialog are a combination of the module they are defined in and their actual name without the preceeding $. So for InsertName.txtFirstName, InsertName is the recording module, then there is a separating period, and txtFirstName is the actual variable name.
For the column LastName:
-
Open the drop-down list of variables next to the data column.
-
Check the variable to use for the data binding. In this case: InsertName.txtLastName
Only unbound variables are displayed. InsertName.txtFirstName is missing because we’ve already bound the column FirstName to it.
Repeat these steps for the remaining columns/variables.
Result
-
List of available data columns from the assigned data source.
-
List of bound variables.
Resulting test suite view
-
Data source myCSVData with 8 data rows assigned to a test case.
-
6 bound variables in 5 recording modules.
Our data-driven test is now complete. In the next chapter, we’ll run it and get our report.
View status in data binding pad
The data binding pad gives you a quick and detailed overview of a test container’s data binding, i.e. its variables and parameters, their status, and their values.
-
To open the data binding pad, click the View data binding button in the toolbar and select a node (for example, an item) in the test suite.
-
The data binding pad displays the data binding information for this node.
-
Data binding pad showing variables bound to a data source.
-
Data binding pad showing variables bound to parameters.
Auto-bind
This option automatically binds all variables to data source columns or parameters of the same name.
Design your variables and data sources to be auto-bindable for quick data binding. An easy way to do so is to create your variables, and then Auto-create a simple data source in the Data-binding dialog.
Auto-bind is available in three places:
- in the data-binding dialog (see further above)
- in the data-binding pad
- in a message displayed when adding/moving a module that has auto-bindable variables
When you auto-bind variables from the data-binding pad or the message and a variable fits both a data-source column and a parameter, then it is auto-bound to the parameter.
Auto-bind from data-binding pad
To auto-bind this way:
-
Select an item with unbound, auto-bindable variables in the test suite.
-
Click Auto-bind in the data-binding pad.
Select the test suite node and click Auto-bind to instantly bind all auto-bindable variables in the entire test suite!
Auto-bind from message
When you add or move a module that contains unbound auto-bindable variables, a message will pop up to ask you if you want to auto-bind these variables. You can also click Remember selection for this solution to always do so automatically.
Data binding in module groups
Data binding for module groups works a little differently than for test containers (test cases, smart folders).
Initially, variables used in recording modules that are inside a module group are not visible in the test suite view. You can only see them if you open the module group.
-
Module group InsertName in the smart folder InsertData.
-
The module group contains two recording modules, each with one defined but unbound variable.
-
These variables are not yet visible in the test suite view and therefore can’t be used. At this point, they’re only visible inside the module group. They are encapsulated in it.
Bind the variables in the module group to data
To make these encapsulated variables visible in the test suite and bind them to data, we need to first bind them to module-group variables. These act as a bridge from inside the module group to the test container.
To bind variables to module-group variables:
-
In the module group view, right-click the module group.
-
Click Data Binding…
-
Add a module-group variable for each recording-module variable and bind the recording-module variables to the module-group variables.
a. You can also bind the recording module variables to constant values. This way, the variables will not be visible/usable in the test suite view, but still be bound to values.
Constant values do not appear in the report either. This is useful for binding variables to values that not everyone who reads the reports should be able to see.
Result
-
The variables are now visible through the module-group variables in the data binding pad…
-
…and can be bound to data sources and parameters in test containers just like other variables.