Lesson 3: Data-Driven Testing

When you test an application it might be necessary to run the same test with different input data. Within the following section you learn about:

Using Variables within Recordings

According to the VIP Database application we can identify four variable input actions:

  • First Name (John)
  • Last Name (Smith)
  • Gender (Male)
  • Category (Music)

All these input actions are done within the AddVip recording. You need to open the recording file and identify the actions which have to be variable.

Data-driven variable for a key sequence action
Create a new variable for a key sequence action item
Open the combo box as shown above and select 'As new Variable' to create a new variable.
Data-driven variable
Create a new variable

Specify the variable name and the default value, which is automatically set to the same value as it was recorded initially. If you want to alter the name or the default values simply open the variables dialog as described here.

Note: Please do not use variable names which are already in use by a recording or code module.

Repeat the previous step to create a variable 'LastName' for the key sequence action used to set the value of the last name field, too.

Using Variables within the Repository

Within the recording 'AddVip' the variables 'FirstName' and 'LastName' are used for key sequence actions. To make a click action data driven - for example selecting the radio button Male or Female - you need to define a variable used for identification within a RanoreXPath expression.

Action variable
Make click action variable
Select that action item within the 'AddVip' recording which simulates the click on a radio button and open the context menu as shown above. Click on 'Make Item Variable...' to open the RanoreXPath editor.
Variable for a radio button
Create a new variable for selecting a radio button

Typically the radio button for the VIP Database application is identified by the controlname attribute. So the attribute controlname is checked by default. Because the test should use the text value as data driven input later on, you need to uncheck the control name attribute and check the text attribute as shown above. Now you can define a new variable for the attribute text by clicking the button on the right.

The same way you created a data driven click action on the radio button, you have to do it with the click action used to select a category item within the list box.

When looking at the repository you see that now two items are using the variables within the path expression specified before.

Renaming repository items

In addition rename the repository items to 'CategoryItem' and 'GenderOption' to clarify for what they can be used.

The recording AddVip now uses 4 variables. Two of them are used for key sequences directly within the recording, while the others are used within the repository. To get an overview about all variables used within the recording simply click the 'Variables' button as shown below.
Recording's test variable dialog
Open the recording's variable dialog
Edit data-driven variables
Currently used variables by the recording

Creating Test Data

As you saw, the recording now uses four variables. In this section you will learn how to create a simple data table to provide the values for these variables. To create a new Ranorex data source you need to open the test suite view.

Select the test case which uses the 'AddVip' recording and open the Data Source dialog by clicking the 'Data Sources' button within the toolbar.

Open the data source dialog
Now create a new data table of type 'Simple Data Table'. Click the column headers to specifiy the column names as shown below. Finish the creation of the data table by defining some data records.
Simple Data Table
Create a new 'Simple Data Table' connector
Data column names
Specify column names
Define test data
Define test data
For further information about different Ranorex data connector types click here: Data Connectors

Combining Variables with Test Data

In order to combine your data table with the current test case - and finally with the AddVip recording which is used by the test case - you need to open the data binding dialog using the context menu as follows:

Data binding dialog
Open data binding dialog
Now you can connect each column specified within the data table with varibles used by the test case. You can also map multiple variables to one data column. Right now you only have variables specified within the 'AddVip' module.
Data columns dialog
Connect data columns with module variables

Combining Variables with Parameters

In additon to typical test data specified within data tables as shown before, a test suite and its test cases allow to declare global and local parameters. These parameters can be bound to module variables too. This type of data driven execution helps to specify for example environment related attributes as the following example describes.

The test case starts with a recording module called 'StartSystemUnderTest'. The recording only contains one single action item used to start the VIP Database application. Open the recording and create a new variabe called 'ApplicationPath'.

New test variable for the execution path
Create new variable for the execution path of the system under test
The execution path of the system under test has to be declared as a global parameter on the test suite level in order to combine it with multiple test cases of the test suite. Use the context menu within the test suite view and open the parameters dialog as follows.
Open global parameters dialog
Define a new global parameter for the test suite

Specify a new parameter name by clicking in the first cell of the column 'Name'. Also specify a value for the new parameter. Just copy and paste the execution path from the default value shown within the variables dialog of the recording 'StartSystemUnderTest'. Read more about how to open a recording's variable dialog here: Recorder Variables

Click 'OK' to apply the changes and to close the dialog.

Now you are ready to combine the global parameter with the variable created within the recording before. Open the test case's data binding dialog the same way you did before for combining variables with the data table.

Combine global parameter with the variable used within recording 'StartSystemUnderTest'

Executing Data Driven Test

Before you execute the data driven test case you have to make sure that the values specified within the data table can be used correctly within the recording 'AddVip'. The values for the first name, last name and gender will not cause any problems during automation, but the values used for the category (Music, Movie, Sport, etc.) will be a problem because of the current visibility state of each item. Remember, you recorded a click on a visible list item within the list box category. When starting the VIP Database application you see that for example the category 'Sport' is not visible. Therefore you need to ensure visibility - using some lines of user code before you simulate the click action - or use a so called 'Invoke Action' to select a list item as shown below.

First, open the recording 'AddVip' and add a new 'Invoke Action' after the existing mouse click action used to select one of the category items.

Data-driven test invoke action item
After adding the new item you need to specify for which repository element the invoke action should be used. Simply open the 'Select Repository Item' dialog as shown below and select the 'CategoryItem'.
Repository Item
Select repository item 'CategoryItem'
After assigning the repository item to the invoke action the recorder provides the methods suitable for the role list item. The category list item only provides a 'Select' method which you can chose as follows.
Choose 'Select' method

Also delete the initial recorded mouse click action (action item #5 shown within picture above), because now the recording uses the new invoke action to select the list item.

Switch back to the test suite view and start your data driven test by clicking the 'Run' button.

Data-driven test report
Report file showing three iterations of the test case
After executing the test suite the report file shows the result for each iteration. The summary chart counts each iteration as a single test case run.