Data binding

Now that we’ve defined our variables and assigned the data source to the test case, we’re ready to connect them. This is called data binding, which is the topic of this chapter.

In this chapter

    tipp icon

    Screencast

    The screencast “Data binding” walks you through information found in this chapter.:

    Watch the screencast now

    Initial situation

    The below image shows the initial situation with the data source assigned to the test case and the defined, but unbound variables next to the recording modules.

    Initial situation for variable binding

    Data source myCSVData with 8 data rows assigned to a test case.
    6 unbound variables in 5 recording modules.

    Access data binding

    Use one of the following options:

    Right-click a test container and click Data binding…

    Double-click an unbound variable.

    Accessing data binding

    The data binding dialog

    The data binding dialog opens with the following items:

    Data binding dialog

    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 will bound. In this case: InsertName.txtFirstName

    Note icon

    Note

    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.

    Binding variables - part I

    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

    Note icon

    Note

    Only unbound variables are displayed. InsertName.txtFirstName is missing because we’ve already bound the column FirstName to it.

    Binding variables - part II

    Repeat these steps for the remaining columns/variables.

    Result

    Finished variable binding

    List of available data columns from the assigned data source.
    List of bound variables.

    Resulting test suite view

    Resulting test suite view with bound variables

    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 (i.e. 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 to parameters of the exact same name.

    tipp icon

    Hint

    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 function

    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
    Note icon

    Note

    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.

    tipp icon

    Hint

    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.
    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.

    tipp icon

    Hint

    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.