Odd/Incorrect DDT Code Example in Documentation
Hi,
I have been learning how to script 'Data Driven Tests' in TestComplete.
The Documentation here : https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/drivers.html
Has some javascript examples which I tried out. But it did not seem to work too well. (You had to choose the Driver function each time)
ie
var RecNo;
// Posts data to the log (helper routine)
function ProcessData()
{
var Fldr, i;
Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo));
Log.PushLogFolder(Fldr);
for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)
Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
Log.PopLogFolder();
RecNo = RecNo + 1;
}
// Creates the driver (main routine)
function TestDriver()
{
var Driver;
// Creates the driver
// If you connect to an Excel 2007 sheet, use the following method call:
// Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", true);
Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
// Iterates through records
RecNo = 0;
while (! Driver.EOF() )
{
ProcessData(); // Processes data
Driver.Next(); // Goes to the next record
}
// Closes the driver
DDT.CloseDriver(Driver.Name);
}
After examining the code I found it was not quite correct (Its like someone messed with it just to try to get it to run)
I have corrected the code in the example to get it to working as I think it was intended.
// Posts data to the log (helper routine)
function ProcessData(RecNo)
{
var Fldr, i;
Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo));
Log.PushLogFolder(Fldr);
for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)
{
Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
}
Log.PopLogFolder();
}
// Creates the driver (main routine)
function TestDriver()
{
var Driver, RecNo;
// Creates the driver
// If you connect to an Excel 2007 sheet, use the following method call:
// Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", true);
Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
// Iterates through records
RecNo = 0;
while (! Driver.EOF() )
{
ProcessData(RecNo); // Processes data
Driver.Next(); // Goes to the next record
RecNo = RecNo + 1;
}
// Closes the driver
DDT.CloseDriver(Driver.Name);
}
I hope it's of use to others 🙂 as it had me baffled for a while.
(NB. Don't forget to press on the '>' symbol, next to each record output in the log, to see the data extracted from your spreadsheet.)
Mike359 , thank you for the idea. I've passed this to the Documentation team!