As in many examples (both in this book, and in the TestComplete documentation) to iterate through the data with the help of the DDT method, the while
loop
is usually applied.
This is not the only method to handle the DDT tables, and in this recipe we will consider another method, namely that of DDTDriver.DriveMethod
.
To go through all the records in the file without the loop, it is necessary to:
function printPersonLastName() { Log.Message(DDT.CurrentDriver.Value("Last")); }
printPersonLastName
with the help of the DriveMethod
method:function testDriveMethod() { var data = DDT.ExcelDriver("C:\drivemethod.xls", "Sheet1"); data.DriveMethod("Unit1.printPersonLastName"); DDT.CloseDriver(data.Name); }
testDriveMethod
is now be launched, the log will contain all of the names from the First
column of the file c:drivemethod.xls
.The DriveMethod
method iterates through all the records in the current driver, each time applying the method, which was passed as a parameter to the DriveMethod
method. The name of the launched method is passed wholly, because it has to contain the name of the module (in our case, the Unit1
) and the name of the function itself (printPersonLastName
). The type of the parameter is string
.
To access the current parameters (properties and methods) of the DDT driver from within the evoked function, we use the
CurrentDriver
property.
Thus, with the help of the DriveMethod
method, we have significantly simplified the code of the scripts, ridding ourselves of the loops and the need to non-forgetfully call the Next
method at the end of the loop.
3.16.137.117