Working With External Data Sources

Applies to TestComplete 12.60, last modified on September 17, 2018

It is often necessary to read data from external files, for example, to compare them with the test data or to use them during data-driven testing. TestComplete provides the ability to read data of various formats from external files.

In This Section

Working With Microsoft Excel Files

Describes the approaches to retrieving data from Excel files.

Working With Databases

Explains how to connect to the needed database and use its data for testing.

Working With Files From Scripts

Describes the ways of working with files from scripts.

To learn how to read external data from tests, see the section below.

Text Files

There are several ways to read data from a text file:

  • Use the aqFile and aqTextFile objects. Using the methods and properties of these objects you can manage text files as well as read data from and write it to the files.

  • You can use the methods of the Scripting.FileSystemObject object to work with text files. To create this object, call the Windows Scripting Host. The Scripting.FileSystemObject object allows you to open text files for reading and writing. For more information on this object, see the FileSystemObject Object article in the MSDN library.

  • You can also use DelphiScript’s native file routines supported by TestComplete to read external files. For more information on DelphiScript file routines, see File and Folder Routines. Note that the other scripting languages do not provide file routines, so, if you use JavaScript, JScript, Python, VBScript, C#Script or C++Script in your tests, you will have to use another way to read external files.

For more information on working with text files, see Reading Text Files.

Binary Files

You can work with binary files in the same way as with text files. To read data from binary files, you can use DelphiScript’s native file routines or properties and methods of the Scripting.FileSystemObject object. You can also use special program objects provided by TestComplete (aqFile and aqBinaryFile). For more information, see above.

INI Files

To read INI files, you can use the INI method of the Storages object. It returns the FileSelection object that provides access to a root section of the INI file. Using the properties and methods of the FileSelection object, you can work with the file’s current section, subsections and their options.

For more information on using the Storages object to read INI files, see Storages Object.

Windows System Registry

TestComplete also allows you to read sections and options stored in the system registry. To do this, use the Registry method of the Storages object. This method returns the Section object for a system registry key. Using the object’s properties and methods you can create and delete sections, subsections and their options and change the sections’ contents.

For more information on working with the system registry, see Reading Sections and Options from the System Registry. Example.

XML Files

There are two different ways to read data from XML files: by using the Storages object and by using the XML DOM object. It is recommended to use the second way because it allows you to read data from XML files of any format while the Storages object works only with XML files of a specific format. The XML DOM object provides scripting access to an XML document and to all of its elements and attributes via the COM interface.

For more information on reading XML files, see Working With XML Files From Scripts.

CSV Files

To read data from CSV files in keyword tests, you can use DB Table variables. These variables can store links to CSV files and provide serial access to data rows stored in these files. DB Table variables are usually used by the Data-Driven Loop operation that allows you to iterate through the file lines in keyword tests. When you are adding this operation to the test, you specify the DB Table variable that will access the specified CSV file and specify the lines that will be processed by the operation. To learn how to use the Data-Driven Loop operation in your tests, see Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.

To read data from CSV files in scripts, use the DDTDriver object that provides scripting access to CSV files. To obtain the driver object in a script, use the DDT.CSVDriver method of the DDT object. The driver represents the stored data as a table and the driver’s methods allow you to iterate through the file lines and read data from the file. Column names of the table are specified by the first line of the CSV file, and table rows correspond to the lines of the CSV files. To get the line of the CSV file, use the Value property of the driver object. For more information on reading CSV files, see Using DDT Drivers.

Microsoft Office Excel Files

To read data from Microsoft Office Excel files in keyword tests, you can use DB Table variables. These variables can store links to Excel files and provide serial access to data rows stored in these files. DB Table variables are usually used by the Data-Driven Loop operation that allows you to iterate through the file rows in keyword tests. When you are adding this operation to the test, you specify the DB Table variable that will access the specified Excel file and specify the records that will be processed by the operation. To learn how to use the Data-Driven Loop operation in your tests, see Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.

To read data from Microsoft Office Excel files in scripts, use the DDTDriver object that provides scripting access to XSL files. To obtain the driver object in a script, use the ExcelDriver method of the DDT object. The driver represents the stored data as a table, the number of its columns and rows is specified by the number of columns and rows of the XSL file. The driver object’s methods allow you to to iterate through the file rows and read the cell values. To get the number of columns in the XSL file, use the ColumnCount property of the driver object, and to obtain column names, use the ColumnName property. To obtain the cell value of the XSL file, use the Value property of the driver object. For more information on reading Excel files, see Using DDT Drivers.

Databases

If your tested application uses the Microsoft Active Data Object to manage databases, you can access the data stored in the database in several ways.

  • Using DB Table variables. These variables can store links to database tables and queries and provide serial access to their records. DB Table variables are usually used by the Data-Driven Loop operation that allows you to iterate through the table records in keyword tests. When you are adding this operation to the test, you specify the DB Table variable that will access the specified database table and specify the records that will be processed by the operation. To learn how to use the Data-Driven Loop operation in your tests, see Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.

  • Using the ADODriver object that provides scripting access to database tables. The driver object represents the stored data as a table, its columns and rows coincide with the rows and columns of the database table. To use the driver object in a script, use the DDT.ADODriver method of the DDT object. The driver object’s methods allow you to iterate through the table or recordset rows and read the field values. For more information on reading database files with the ADODriver object, see Using DDT Drivers.

  • Using the ADO program object. The ADO object’s methods allow you to connect to a database, create tables and datasets, work with records and queries. For more information on working with databases with the ADO object, see Working With Databases.

See Also

Data-Driven Testing
Working With Files From Scripts
Reading Text Files
Working With XML Files From Scripts
DDT.CSVDriver Method
DDT.ExcelDriver Method
Working With Databases
Storages Object

Highlight search results