How to Create Data-Driven Tests with DB Table Project Variables

October 4, 2013
Let us consider a recorded test automation script for a scenario in an application. In that script, we have the test data which we entered into our application while recording the test. If you execute the script, it will use exactly the same test data. However, this approach isn’t scalable and forces you to use the same test data every time your run the script. So ideally we should create test scenarios with a range of different test data. If your application has a scenario, which needs to be tested with different test data, then you can go with data-driven framework for automated testing. A Data-Driven framework is an excellent test automation framework, which gives good test coverage with minimal scripting. Common Steps involved in Data driven Testing:
  • Create your test with a set of test data.
  • Replace your test data with some variables.
  • Keep multiple sets of test data in data storage (Excel or csv etc.)
  • Now write the script to read the first test of test data from the data storage and assign those values to those variables. While executing, the script will use the test data which are read from the data storage.
  • Write a loop statement, to perform the above step for all the sets of test data in the data storage.
In Testcomplete, we have different options to create a data driven test. In testcomplete we can easily access the data from data stores like excel, csv, Data base tables etc. For accessing data from these data stores we can use the DDT driver object, DB table variables, and Table variables. Also, in a keyword test we can use the ‘Data Driven Loop wizard‘ to create data driven testing. We’re going to see how to create a data driven test for a small script using DB table variables. We will use an excel sheet as our data store.
    1. Let us take the following script. This script is used to perform login action in a login window and then it verifies that the welcome message is displayed.


    1. Here the user name & password values are the test data. In the above script these values are hard coded. But we want to test this script with different sets of username & password, which are stored in an excel sheet as below. So we have to parametrize these two values.
    1. To access values from the excel sheet, first we need to create a DB table variable. To create a DB table variable complete following steps.
        • Open the Project variables window.


        • Right click on Temporary Variables window and select New Item option.
        • Now you can see a new Project variable row. In which enter a Variable name & select the Type as ‘DB Table‘. In our example, the variable name is given as ‘Login_Data‘.
    2. Now, Click on the ‘Default Value‘ cell and click on the Ellipsis button.
    1. It will open ‘Edit DB Table variable‘ window, in which select the Data source type as ‘Excel worksheet‘ and click ‘Next‘ button.
    1. Now click on the Ellipsis button in the ‘File Name‘ Textbox and select the excel file in which the test data are stored. Then click Next button.
    1. Now, select the work sheet name of excel workbook, in which the test data are stored. Also ensure that, the ‘Treat the first row as column names‘ checkbox is checked. Now, click Finish button.
    1. Now we have created a DB table variable for the excel sheet object. Now to access a value from a cell, we have to use the following code. By default the variable pointer will be in the first row of the excel sheet. So now the following code will return you the values in first row.Project.Variables.Login_Data.Value(“Login Name”) (Returns value in the “Login name” column of first row) Project.Variables.Login_Data.Value(“Password”) (Returns value in the “Password” column of first row
    2. Now, in the script, replace the hard coded values with these two variables.


    1. The above script will enter login details, which are read from the first row of excel sheet. Now if you want to execute this for all the rows, you have to move the variable pointer to each row of excel sheet and execute the script.


If your excel sheet has 10 rows, this test will be executed for ten times.