Driving data without using loops

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.

Getting ready

Create the file c:drivemethod.xls with the following content:

Getting ready

How to do it...

To go through all the records in the file without the loop, it is necessary to:

  1. First create a function that will read all of the data from the currently handled column of the table:
    function printPersonLastName()
    {
      Log.Message(DDT.CurrentDriver.Value("Last"));
    }
  2. Create the function, which will call the earlier written function: 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);
    }
  3. If the function testDriveMethod is now be launched, the log will contain all of the names from the First column of the file c:drivemethod.xls.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.117