TestComplete samples (both built-in and additional) are located in the <Users>\Public\Public Documents\TestComplete 14 Samples folder.
Some file managers display the Public Documents folder as Documents.
Description
TestComplete includes special program objects that let you easily access data stored in an Excel sheet, CSV file or in an ADO database table. These objects are called drivers. They are typically needed to perform data-driven tests, however, you can also use them to retrieve data from the mentioned storages.
The DDT
object is used to create drivers for ADO database tables, Excel sheets and files holding comma-separated data (CSV file). Its methods return special “driver” objects that have access to values stored in the mentioned data storages.
Note: | The object is only available if the Data-Driven Testing plugin is installed in TestComplete. See Using DDT Drivers. |
Members
Example
The TestProc
procedure connects to the specified database, retrieves information about the text of the command used by the database’s table, posts this command text to the test log, and then closes the connection to the database.
Notes:
-
This example uses the OrdersDB.mdb file that is part of the additional sample package. To use it, download this package from support.smartbear.com/downloads/testcomplete/samples/ and install it. After the installation is over, you can find the database in the <TestComplete 14 Samples>\Desktop\Checkpoints\XML\DataGridViewSample folder.
-
Using the Microsoft.Jet.OLEDB.4.0 provider requires that you run your script in the 32-bit version of TestComplete.
TestComplete 32-bit executable is located in the <TestComplete>\Bin folder.
JavaScript, JScript
function TestProc()
{
// Specify the connection string
var ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the name of the table
var tName = "orders";
// Obtain the ADO Command text
var cText = DDT.ADODriver(ConStr, tName).ADOCommandObject.CommandText;
// Post this command text to the test log
Log.Message(cText);
// Close the connection to the specified database
DDT.ADODriver(ConStr, cText).ADOConnectionObject.Close();
}
Python
def TestProc():
# Specify the connection string
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"
# Specify the name of the table
tName = "orders"
# Obtain the ADO Command text
cText = DDT.ADODriver(ConStr, tName).ADOCommandObject.CommandText
# Post this command text to the test log
Log.Message(cText)
# Close the connection to the specified database
DDT.ADODriver(ConStr, tName).ADOConnectionObject.Close()
VBScript
Sub TestProc
' Specify the connection string
ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb"
' Specify the name of the table
tName = "orders"
' Obtain the ADO Command text
cText = DDT.ADODriver(ConStr, tName).ADOCommandObject.CommandText
' Post this command text to the test log
Log.Message(cText)
' Close the connection to the specified database
DDT.ADODriver(ConStr, tText).ADOConnectionObject.Close
End Sub
DelphiScript
function TestProc;
var ConStr, tName, cText;
begin
// Specify the connection string
ConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb';
// Specify the name of the table
tName := 'orders';
// Obtain the ADO Command text
cText := DDT.ADODriver(ConStr, tName).ADOCommandObject.CommandText;
// Post this command text to the test log
Log.Message(cText);
// Close the connection to the specified database
DDT.ADODriver(ConStr, cText).ADOConnectionObject.Close();
end;
C++Script, C#Script
function TestProc()
{
// Specify the connection string
var ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the name of the table
var tName = "orders";
// Obtain the ADO Command text
var cText = DDT["ADODriver"]( ConStr, tName )["ADOCommandObject"]["CommandText"];
// Post this command text to the test log
Log["Message"](cText);
// Close the connection to the specified database
DDT["ADODriver"](ConStr, cText)["ADOConnectionObject"]["Close"]();
}
See Also
Using DDT Drivers
DDTDriver Object
Data-Driven Testing
Using Scripts for Data-Driven Testing