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 XML Files From Scripts
Working With Microsoft Excel Files
Working With Files From Scripts
For general information on reading data from files, see the sections below:
Text Files
-
Use the
aqFile
andaqTextFile
objects. This way, you can manage text files as well as read data from and write it to the files. -
Use the
Scripting.FileSystemObject
object. To get this object, call the Windows Scripting Host. The object allows opening text files for reading and writing. For more information, see docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/z9ty6h50(v=vs.84). -
If you use DelphiScript, you can use its native file routines to read external files. For more information, see File and Folder Routines.
Note: The other scripting languages do not provide file routines. 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, see Reading Text Files.
Binary Files
You can work with binary files in the same way as with text files:
-
You can use DelphiScript native file routines.
-
You can use the
Scripting.FileSystemObject
object. -
You can use program objects provided by TestComplete:
aqFile
andaqBinaryFile
.
For more information, see above.
INI Files
To read INI files, you can use the Storages.INI
object. It provides access to a root section of the INI file. Using the object, you can work with the file’s current section, subsections and their options.
For more information, see Storages Object.
Windows System Registry
You can read sections and options stored in the Windows system registry. To do this, use the Storages.Registry
method. This method returns the Section
object for a system registry key. Using the object, you can create and delete sections, subsections and their options and change the section contents.
For more information, 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. This approach is applicable only to XML files of a specific format. -
By using the
XML DOM
object (recommended). It allows reading data from XML files of any format. The object provides scripting access to an XML document and to all of its elements and attributes via the COM interface.
For more information, 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. Usually, you use DBTable variables in Data-Driven Loops to iterate through file lines. See Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.
To read data from CSV files in scripts, use the DDT.CSVDriver
object that provides scripting access to CSV files. The driver represents the stored data as a table and allows iterating through the file lines and read data from it. For more information, 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. Usually, you use these variables in Data-Driven Loops to iterate through file rows. To learn more, 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 DDT.ExcelDriver
object. The driver represents the stored data as a table and allows iterating through the file rows and reading cell values. For more information, 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:
-
By using DB Table variables. These variables can store links to database tables and queries and provide serial access to their records. You usually use these variables in Data-Driven Loop to iterate through the table records.
To learn more, see Creating Data-Driven Loops and Data-Driven Testing With Keyword Tests - Tutorial.
-
By using the
DDT.ADODriver
object that provides scripting access to database tables. The driver object represents the stored data as a table. The object allows iterating through the table or recordset and reading the field values. For more information, see Using DDT Drivers. -
Using the
ADO
program object. The object allows connecting to a database, creating tables and datasets and working with records and queries. For more information, 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