QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

QuickTest Professional script Debugging using File Operations

Share This Post -

Sponsored Links:

The following are some file operations which are useful for debugging scripts in QTP. The following examples can be downloaded from here.

' Creates a specified file and returns a TextStream object that can be used to read from or write to the file.

' Example of usage:

' Set f = CreateFile("d: emp\beenhere.txt", True)

' f.WriteLine Now

' f.Close

Function CreateFile(sFilename, bOverwrite)

Set fso = CreateObject("Scripting.FileSystemObject")

Set CreateFile = fso.CreateTextFile(sFilename, bOverwrite)

End Function

' Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.

' iomode: 1 - ForReading, 2 - ForWriting, 8 - ForAppending

' Example of usage

' Set f = OpenFile("d: emp\beenhere.txt", 2, True)

' f.WriteLine Now

' f.Close

Function OpenFile(sFilename, iomode, create)

Set fso = CreateObject("Scripting.FileSystemObject")

Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)

End Function

' Appends a line to a file.

' Example of usage:

' AppendToFile "d: emp\beenhere.txt", Now

Function AppendToFile(sFilename, sLine)

Const ForAppending = 8

If sFilename = "" Then

sFilename = Environment("SystemTempDir") & "\QTDebug.txt"

End If

Set f = OpenFile(sFilename, ForAppending, True)

f.WriteLine sLine

f.Close

End Function

' Writes a line to a file.

' Destroys the current content of the file .

' Example of usage:

' WriteToFile "d: emp\beenhere.txt", Now

Function WriteToFile(sFilename, sLine)

Const ForWriting = 2

If sFilename = "" Then

sFilename = Environment("SystemTempDir") & "\QTDebug.txt"

End If

Set f = OpenFile(sFilename, ForWriting, True)

f.WriteLine sLine

f.Close

End Function