Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
QTP and File Handling

QTP and File Handling

Ratings: (0)|Views: 185 |Likes:
Published by api-19840982

More info:

Published by: api-19840982 on Nov 30, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

QTP and File Handling

Many a times you may need to interact with text files using QTP. Interaction can be(but not limited to) in the form of reading input from a file, writing output to a file. This post describe in detail "File handling using QTP".

What is FSO?

FSO stands for File System Object. This is used to support text file creation and manipulation through theTex tStream object and is contained in the Scripting type library

(Scrrun.dll) The FSO Object Model has a rich set of properties, methods and events to process folders and files.

How to create a file?
We first create a FSO object using CreateObject and then create a text file using
CreateTextFile.
For Example: Suppose you want to create a file called "test.txt" located in C:

Dim fso, file, file_location
file_location = "C:\file_location"
Set fso =Cre at e Ob je ct(\u201cScripting.FileSystemObject\u201d)
Set file = fso.CreateTextFile(file_location, True) // True--> file is to be overwritten if it
already exists else false

We would use the same example for the rest of this post.
How to open a file?

Set file= fso.OpenTextFile("C:\file_location", ForWriting, True)
//2nd argument can be ForReading, ForWriting, ForAppending
//3rd argument is "True" if new file has to be created if the specified file doesn\u2019t exist
else false, blank signify false.

How to read content from a file?

Use ReadLine() method
For example:
Set file= fso.OpenTextFile("C:\file_location", ForReading, True) //2nd argument should
always be "ForReading" in order to read contents from a file
Do while file.AtEndofStream <> True

data = file.ReadLine()
msgbox data
Loop
How to write content to a file?

You can use Write() or WriteLine() Methods to write text into a file. The difference
between the Write() and WriteLine() Method is that the latter automatically inserts a
new line character while the former doesn\u2019t insert a new line character.
For example:
Set file= fso.OpenTextFile("C:\file_location", ForWriting, True) //2nd argument should
always be "ForWriting" in order to write contents to a file

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->