file system object in qtp

10

Upload: praveen-gorantla

Post on 22-Apr-2015

902 views

Category:

Education


3 download

DESCRIPTION

File System Object in QTP

TRANSCRIPT

Page 1: File System Object in QTP
Page 2: File System Object in QTP

What is FileSystemObject Model?

Create FSO

Creating text files using FSO

Reading contents from a File

Writing text to a File

Deleting a File

Session Wrap-Up

pgorantla.blogspot.com

File Handling using FSO

Page 3: File System Object in QTP

The FSO object model is contained in the Scripting type library (Scrrun.dll), supports text file creation and manipulation through the TextStream object.

The FSO object model gives the server-side applications the ability to create, alter, move, and delete folders, or to detect if particular folders exist, and if so, where.

You can also find out information about folders, such as their names, the date they were created or last modified, and so forth.

Create FSO ObjectsFSO Objects can be created using the CreateObject Method. Dim myfsoSet myfso = CreateObject (“Scripting.FileSystemObject”) ‘Creating a FSO and then assigning it to myfso

pgorantla.blogspot.com

File Handling using FSO

Page 4: File System Object in QTP

Creating Text Files using FSO. CreateTextFile method of FSO helps to create

text files. fsoObject.CreateTextFile (filename [, overwrite [,

Unicode]]) as TextStream. Parameters

Filename – The Filename for the file to be created Overwrite – Boolean value indicating whether to

overwrite the file if it already exists. If the file is to be overwritten, the value set is true, else false. Blank denotes the files are not overwritten.

Unicode – Boolean value indicating the nature of the text file ie., whether the file to be created as a Unicode or an ASCII file. The value set is True for Unicode, else False. Blank denotes ASCII files.

Returns TextStream Object

pgorantla.blogspot.com

File Handling using FSO

Page 5: File System Object in QTP

The ReadLine() Method is used to read the contents of a text file. Alternatively, Read() and ReadAll() methods can be used to achieve the same objective.

Syntax for OpenTextFile() is Object.OpenTextFile(filename[, iomode[, create[,

format]]]) Parameters

Filename – Name of the file to be opened.

Iomode - Optional. The Mode in which the file has to be opened. The value can toggle between these three modes: ForReading, ForWriting, ForAppending

Create – Optional. Boolean value that indicates whether a new file can be created if the specified file doesn’t exist. The value is true if new file has to be created, else false. If blank, then new file isn’t created.

Format – Optional. Values toggle between 3 states. Whether the file has to be opened as Unicode, opened as ASCII or use the system default pgorantla.blogspot.com

File Handling using FSO

Page 6: File System Object in QTP

pgorantla.blogspot.com

• ReadLine() – Reads all the characters till the newline character is encountered. I.e., it

reads an entire line.

– Syntax• Object.ReadLine()

File Handling using FSO

Page 7: File System Object in QTP

The Write() and WriteLine() Methods are used 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’t insert a new line character.

pgorantla.blogspot.com

File Handling using FSO

Page 8: File System Object in QTP

The DeleteFile() or Delete() Method can be used to delete the file.

sample code

pgorantla.blogspot.com

File Handling using FSO

Page 9: File System Object in QTP

pgorantla.blogspot.com

Q & A….

File Handling using FSO

Page 10: File System Object in QTP

FSO objects are part of Scripting Library. The methods and properties of FSO Objects empowers

the user to work with files and folders. FSO Objects can be created using the CreateObject

Method. CreateTextFile method of FSO is used for creating text

files OpenTextFile method of FSP is used for opening text

files. The text files can be opened in 3 modes: ForReading – the file is opened in Read Only Mode ForWriting – the file is opened in ReadWrite Mode ForAppending – the file is opened in ReadAppend Mode

The Read() and ReadLine() Method is used for reading contents line by line from the Text file.

The Write() and WriteLine() Method are used for writing contents to the file.

The DeleteFile() or Delete() Method can be used to delete the file.

pgorantla.blogspot.com

File Handling using FSO