Header Ads

Read from a .txt file through QTP

How to read from a flat file. you know what reading from flat files required to perform data driven testing mostly.
Excell is bit heavy to perform such operation and a .txt file can be treated as input to QTP.
Here is a sample code to read from a .txt file. by this procedure you can read character one by one.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("D:\test.txt", 1)
Do Until objFile.AtEndOfStream
strCharacters = objFile.Readline
msgbox strCharacters
Loop

again one question might come to our mind how to get exactly the word or phase..you are looking by one character

here is the ans...

Dim fso,myfile
Set fso=createobject("scripting.filesystemobject")
Set myfile= fso.opentextfile ("D:\test.txt",1)
myfile.skipline
While myfile.atendofline <> True
x=myfile.readline
s=split (x, ";")

here we are splitting by ";".
Powered by Blogger.