I want to use a text file for data in QTP 11

  • Questions
  • I want to use a text file for data in QTP 11
Question ID: 104835

I have a comma delimited file that I’d like to use for data input in my script, but I don’t want to load it into Excel to be a data table as that would take too long and this data is generated by the application. Can I use this data in my script for input into text fields?

Marked as spam
Posted by (Questions: 188, Answers: 22)
Asked on February 1, 2013 3:25 am
Answers (1)
Private answer

I've done this before using the FileSystemObject in VBScript. You can read in text from basically any type of text file that could be read by Notepad in Windows. I'll give you some sample code to let you try this with in your test.

Basically, you will need to create a loop that continues reading lines from your text file until it reaches the end of file (the end of the text stream). You read the line in to a variable, and then we need to use the VBScript 'Split' operation to chop the string up using the commas as delimeters (separators). This will create a dynamic zero-based array that we can then use to populate the fields using the index number of the array value for input. You would need to make sure that there would be enough values for use as input in your application:

Set FSO = CreateObject(''Scripting.FileSystemObject'')
Set FS = FSO.OpenTextFile(''C:DataFilesMyData.txt'',1) 'open file for reading

Do While FS.AtEndOfStream <> True
MyLine = FS.ReadLine

MyArray = Split (MyLine, '','') 'split using the comma. Use whatever delimeter you wish here

'Use array values for input
Window(''Window'').WinEdit(''Field 1'').Set MyArray(0)
Window(''Window'').WinEdit(''Field 2'').Set MyArray(1)
Window(''Window'').WinEdit(''Field 3'').Set MyArray(0)

Loop ' Repeat until data runs out

Set FS = Nothing
Set FSO = Nothing

Marked as spam
Posted by (Questions: 2, Answers: 438)
Answered on February 1, 2013 3:28 am