TestComplete Data Driven Automated Testing – Write CSV file data.

The below function write array of row values to csv file by creating file object.

Sample:

Sub Utill_WriteCSV(FILENAMEW,WriteFileArray)

Dim objStream
Dim objFSO
Dim innerIndexW

Set objFSO = CreateObject("Scripting.FileSystemObject")

If not objFSO.FileExists(FILENAMEW) Then

Call Log.Error("The File Path " & FILENAMEW & " cannot be found.", HIGHEST_PRIORITY)

Else
Set objStream = objFSO.OpenTextFile (FILENAMEW,8, True)
Call Log.Message("The File Path " & FILENAMEW & " was Found.")

For innerIndexW = 1 to UBound(WriteFileArray)
objStream.WriteLine(WriteFileArray(innerIndexW))
next

End If

objStream.Close()

End Sub (Note: this code based on VB scripts)

Function Steps:

1. Save file path as constant in main function and pass to above < Utill_WriteCSV(FILENAMEW,WriteFileArray)> function.

2. Create a file object for write Functionality.
E.g. Set objFSO = CreateObject("Scripting.FileSystemObject")

3. Verify file object exist for write Functionality.
e.g.

If not objFSO.FileExists(FILENAMEW) Then
Call Log.Error("The File Path " & FILENAMEW & " cannot be found.", HIGHEST_PRIORITY)

Else

4. Open file object and write file values starting from second line (since first line considered as “Field title” row).

e.g. objStream.WriteLine(WriteFileArray(innerIndexW))

Comments

1 Response to "TestComplete Data Driven Automated Testing – Write CSV file data."

Krish said... October 28, 2011 at 4:09 PM

Thanks i like your explanation

Post a Comment