DDT.CSVDriver Method

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

Use the CSVDriver method to create a DDT driver for a CSV file that contains values separated with the predefined delimiter character. You can use this driver to iterate through the lines of the file, obtain values stored in these lines and use these values in your data-driven tests. The driver assumes the first line of the file holds the column names (see Using DDT Drivers).

Declaration

DDT.CSVDriver(FileName)

FileName [in]    Required    String    
Result A DDTDriver object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

FileName

The fully qualified name of the desired CSV file.

Result Value

The DDTDriver object that provides access to data stored in the specified CSV file.

Remarks

The DDT object is only available if the Data-Driven Testing plugin is installed.

For information on working with DDT drivers, see Using DDT Drivers.

For information on specifics and limitations of the CSV DDT driver, see Using CSV Files as Data Storages.

Example

The code below creates a CSV driver, uses this driver to iterate through a file's contents and then closes the driver's access to the file's data.

JavaScript, JScript

function CSVDriverExample()
{
  // Creates a driver
  DDT.CSVDriver("C:\\MyFile.txt");
   
  // Iterates through records
  while (! DDT.CurrentDriver.EOF())
    //...
    DDT.CurrentDriver.Next();
   
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);
  
}

Python

def CSVDriverExample():
  # Creates a driver 
  DDT.CSVDriver("C:\\MyFiles\\MyFile.txt")
  # Iterates through records 
  while not DDT.CurrentDriver.EOF():
    # ...
    DDT.CurrentDriver.Next()
  # Closes the driver 
  DDT.CloseDriver(DDT.CurrentDriver.Name)

VBScript

Sub CSVDriverExample
  
  ' Creates a driver
  DDT.CSVDriver("C:\MyFile.txt")
   
  ' Iterates through records
  While Not DDT.CurrentDriver.EOF()
    '...
    DDT.CurrentDriver.Next()
  WEnd
   
  ' Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name)
  
End Sub

DelphiScript

function CSVDriverExample;
begin

  // Creates a driver
  DDT.CSVDriver('C:\MyFile.txt');
   
  // Iterates through records
  while not DDT.CurrentDriver.EOF() do
    //...
    DDT.CurrentDriver.Next();
   
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);
  
end;

C++Script, C#Script

function CSVDriverExample()
{
  // Creates a driver
  DDT["CSVDriver"]("C:\\MyFile.txt");
   
  // Iterates through records
  while ( ! DDT["CurrentDriver"]["EOF"]() )
    //...
    DDT["CurrentDriver"]["Next"]();
   
  // Closes the driver
  DDT["CloseDriver"]( DDT["CurrentDriver"]["Name"] );
  
}

See Also

DDTDriver Object
Using DDT Drivers
Using CSV Files as Data Storages
Data-Driven Testing

Highlight search results