Data-Driven Testing - Retrieving Input Data From Storage

Applies to TestComplete 15.40, last modified on March 25, 2022

A typical data-driven test performs the following operations in a loop:

  • Retrieves input data from storage
  • Enters it in an application form
  • Verifies the results
  • Continues with the next set of input data

For instance, often data is stored in a text file and are separated by commas (CSV). This lets you modify them easily. If you need to add more data, you simply modify the file in any text editor (in case of hard-coded values, you should modify both data and code). Each string in the file holds values to be assigned or checked. Normally, each string holds values for one test. However, you are free to use several strings for one test. In this case, you may need to add a field that will specify which values are input, and which are verifying values.

For information on data storages that TestComplete supports, see Data Storages.

TestComplete includes special keyword test operation, built-in routines and program objects that provide extended support for data-driven testing.

Keyword Test Operations

To simplify access to data stored in Excel sheets, ADO databases or CSV files from keyword tests, TestComplete includes the special Data-Driven Loop keyword test operation that allows you to create data-driven loops and iterate through the storage’s records. When you are adding this operation to the test, you specify the DB Table variable that will access the specified storage, and specify the records that will be processed by the operation.

You can also retrieve data from TestComplete Table variables. For this purpose, use the Data-Driven Loop keyword test operation. Note that you can specify the default data that will be stored in the variable manually or generate test data using a special TestComplete wizard.

For more information on how to use the Data-Driven Loop operation in tests, see Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.


Routine Description
DDT This object provides access to drivers that let you easily extract data from Excel spreadsheets, database tables and CSV files.
aqString.GetListLength, aqString.GetListItem These methods are used to process a list of strings. To parse comma-separated values, you should previously assign a comma (",") to the aqString.ListSeparator property.
Evaluate function Evaluates an expression or executes a routine by its name.
aqObject.CallMethod Calls an object's method by the method name.
aqObject.GetPropertyValue and aqObject.SetPropertyValue Retrieves and sets a property value by its name.

The last three methods, CallMethod, GetPropertyValue and SetPropertyValue, let you modify the methods sequence and properties to be called by a script without having to modify the script code.

Program Objects

To simplify access to data stored in Excel sheets, ADO databases or CSV files, TestComplete includes special driver objects that hide the actual data storage format and let you access data using a unified table-like interface. For instance, each row of a CSV file is represented as a table record, and a value in this row is presented as a column value.

To work with the drivers, use the DDT object. Its methods let you obtain driver objects for Excel sheets, ADO tables and CSV files:

Method Description
ADODriver Returns a driver object for the specified ADO table.
CSVDriver Returns a driver object for the specified CSV file.
ExcelDriver Returns a driver for the specified Excel sheet.

Changing the Data Type of the Retrieved Value

TestComplete uses DDT Drivers to retrieve information from a storage. In most cases, the data is retrieved as a string. However, it can also be retrieved as an integer. Some methods perform different actions depending on whether you use integers or strings. For example, the ClickItem action performs a touch on an item using its index if you use an integer, but if you use a string, it searches for the corresponding item caption.

If you need to change the data type, use the VarToStr and VarToInt methods to make sure that you use a string or an integer value.

To use these methods in keyword tests, do the following:

  1. Double-click the Value cell of the Keyword Test operation to open the Parameters Editor.
  2. Click the ellipsis button.
  3. Copy the contents of the Value field to the Clipboard.
  4. Change the Mode option to Code Expression.
  5. In the value column, type in either VarToStr() or VarToInt().
  6. Paste the Clipboard contents inside the parentheses and click OK.

In scripts, use these methods to change the data type of the value you retrieve, for example, VarToStr(Driver.Value(5)).

See Also

Data-Driven Testing
Using DDT Drivers
Preparing Data for Data-Driven Testing
Data Generator Wizard

Highlight search results