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.
The following code illustrates how you can use the IAQAADODataset
object, based on the TADODataset class. The TestProc
routine retrieves fields from the source database and posts them to the test log.
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()
{
var DSet, name, cost, discount;
// Create a new IAQAADODataset object
DSet = ADO.CreateADODataset();
// Specify the connection string
DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the command type and text
DSet.CommandType = cmdTable;
DSet.CommandText = "products";
// Open the dataset
DSet.Open();
// Process records of the products table
Log.AppendFolder("Products")
DSet.First();
while (! DSet.EOF)
{
// Insert data into the test log
name = DSet.FieldByName("name").Value;
cost = DSet.FieldByName("cost").Value;
discount = DSet.FieldByName("discount").Value;
Log.Message(name + " - " + "cost: " + cost + "$"+ ", " + "discount: " + discount + "%");
DSet.Next();
};
DSet.Close();
}
Python
def TestProc():
# Create a new IAQAADODataset object
DSet = ADO.CreateADODataset()
# Specify the connection string
DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + \
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb"
# Specify the command type and text
DSet.CommandType = cmdTable
DSet.CommandText = "products"
# Open the dataset
DSet.Open()
# Process records of the products table
Log.AppendFolder("Products")
DSet.First()
while not DSet.EOF:
# Insert data into the test log
name = DSet.FieldByName("name").Value
cost = DSet.FieldByName("cost").Value
discount = DSet.FieldByName("discount").Value
Log.Message("{name} - cost: {cost}$, discount: {discount}%".format(name=name, cost = cost, discount = discount))
DSet.Next()
DSet.Close()
VBScript
Sub TestProc
' Create a new IAQAADODataset object
Set DSet = ADO.CreateADODataset
' Specify the connection string
DSet.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb"
' Specify the command type and text
DSet.CommandType = cmdTable
DSet.CommandText = "products"
' Open the dataset
DSet.Open
' Process records of the products table
Log.AppendFolder("Products")
DSet.First
While Not DSet.EOF
' Insert data into the test log
str = aqString.Format("%s - cost: %d$, discount: %d%%", DSet.FieldByName("name").Value, _
DSet.FieldByName("cost").Value, DSet.FieldByName("discount").Value)
Log.Message(str)
DSet.Next
Wend
DSet.Close
End Sub
DelphiScript
procedure TestProc;
var DSet, str;
begin
// Create a new IAQAADODataset object
DSet := ADO.CreateADODataset;
// Specify the connection string
DSet.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source=C:\Users\Public\Documents\TestComplete 14 Samples\Desktop\Checkpoints\XML\DataGridViewSample\OrdersDB.mdb';
// Specify the command type and text
DSet.CommandType := cmdTable;
DSet.CommandText := 'products';
// Open the dataset
DSet.Open;
// Process records of the Products table
Log.AppendFolder('Products');
DSet.First;
while not aqConvert.VarToBool(DSet.EOF) do
begin
// Insert data into the test log
str := aqString.Format('%s - cost: %d$, discount: %d%%', DSet.FieldByName('name').Value, DSet.FieldByName('cost').Value, DSet.FieldByName('discount').Value);
Log.Message(str);
DSet.Next;
end;
DSet.Close;
end;
C++Script, C#Script
function TestProc()
{
var DSet, name, cost, discount;
// Create a new IAQAADODataset object
DSet = ADO["CreateADODataset"]();
// Specify the connection string
DSet["ConnectionString"] = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Users\\Public\\Documents\\TestComplete 14 Samples\\Desktop\\Checkpoints\\XML\\DataGridViewSample\\OrdersDB.mdb";
// Specify the command type and text
DSet["CommandType"] = cmdTable;
DSet["CommandText"] = "products";
// Open the dataset
DSet["Open"]();
// Process records of the products table
Log["AppendFolder"]("Products");
DSet["First"]();
while (!DSet["EOF"])
{
// Insert data into the test log
name = DSet["FieldByName"]("name")["Value"];
cost = DSet["FieldByName"]("cost")["Value"];
discount = DSet["FieldByName"]("discount")["Value"];
Log["Message"](name + " - " + "cost: " + cost + "$" + ", " + "discount: " + discount + "%");
DSet["Next"]();
};
DSet["Close"]();
}