Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Examples:
i) Create a Folder
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.CreateFolder C:\NageshQtp
ii) Check if the Folder Exist or not? If not create the Folder
myFolder=C:\NageshQtp
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.CreateFolder (myFolder)
End If
myFolder=C:\Nagesh\Qtp
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.CopyFolder myFolder,E:abcd
myFolder=C:\NageshQtp
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.DeleteFolder( myFolder)
2nd
myFolder=C:\NageshQtp
Set objFso=CreateObject(scripting.FileSystemObject)
If objFso.FolderExists(myFolder) Then
objFso.DeleteFolder( myFolder)
End If
Set objFso=CreateObject(scripting.FileSystemObject)
Set colDrives=objFso.Drives
Msgbox oDrive
Next
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
Set myDrive=objFso.GetDrive(D:)
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.CreateTextFile (C:\NageshQtp1.txt)
objFso.CreateTextFile (C:\NageshQtp2.doc)
objFso.CreateTextFile (C:\NageshQtp3.xls)
objFso.CreateTextFile (C:\NageshQtp4.pdf)
Note: We can Create other files also, but they act as Text/Flat Files
viii) Check if the File Exist or not? If not create the File
myFile1=C:\NageshQtp1.txt
myFile2=C:\NageshQtp2.doc
myFile3=C:\NageshQtp3.xls
myFile4=C:\NageshQtp4.pdf
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.CreateTextFile (myFile1)
End If
objFso.CreateTextFile (myFile2)
End If
objFso.CreateTextFile (myFile3)
End If
objFso.CreateTextFile (myFile4)
End If
ix) Read Data Character by Character from a text file
Set objFso=CreateObject(scripting.FileSystemObject)
Do Until myFile.AtEndOfStream=True
myChar=myFile.Read(1)
Msgbox myChar
Loop
myFile.Close
Set objFso=Nothing
Set objFso=CreateObject(scripting.FileSystemObject)
Do Until myFile.AtEndOfStream=True
myChar=myFile.ReadLine
Msgbox myChar
Loop
myFile.Close
Set objFso=Nothing
xi) Data Driven Testing by fetching Test data directly from a Text file.
*****************************************************************************
********
Test Requirement: Data Driven Testing by fetching Test data directly from a Text file.
Author: xyz
Pre-requasites:
Test Flow:
Open the file with Read mode and store reference into a variable
Login Operation
*****************************************************************************
********
Set objFso=CreateObject(scripting.FileSystemObject)
myFile.SkipLine
myLine=myFile.ReadLine
myField=Split(myLine,,)
Wait 2
Dialog(text:=Login).WinButton(text:=OK).Click
Window(text:=Flight Reservation).Close
Loop
myFile.Close
Set objFso=Nothing
a=10: b=20
Result=a+b
Set objFso=CreateObject(scripting.FileSystemObject)
myFile.Close
Set objFso=Nothing
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
objFso.DeleteFile(C:\NageshQtp.doc)
Set objFso=Nothing
xiv) Check if the File Exists or not? If Exists delete the File
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
If objFso.FileExists(C:\NageshQtp1.pdf) Then
objFso.DeleteFile(C:\NageshQtp.pdf)
End If
Set objFso=Nothing
Dim objFso
Set objFso=CreateObject(scripting.FileSystemObject)
File_Size= objFso.GetFile(C:\NageshQtp.txt).Size
Set objFso=Nothing
Option Explicit
File1=C:\NageshQtp.txt
File2=C:\Nagesh.txt
Set objFso=CreateObject(scripting.FileSystemObject)
End If
Set File_First=objFso.OpenTextFile(File1)
Set File_Second=objFso.OpenTextFile(File2)
myFile1=File_First.ReadAll
myFile2=File_Second.ReadAll
Msgbox myFile1
If Files_Compare=0 Then
Else
End If
If Files_Compare=0 Then
Else
End If
Set objFso=Nothing
xvii) Count the number of times a word appears in a Text File
Option Explicit
File1=C:\NageshQtp.txt
Set objFso=CreateObject(scripting.FileSystemObject)
Set myFile=objFso.OpenTextFile(File1)
myData=myFile.ReadAll
myWord=QTP
TotMatches=MatchesFound.Count
Set objFso=Nothing
Option Explicit
FilePath=C:\NageshQtp.txt
Set objFso=CreateObject(scripting.FileSystemObject)
Set myFile=objFso.OpenTextFile(FilePath,2)
myFile.WriteLine Button Names
myFile.WriteLine
Set oButton=Description.Create
oButton(micclass).value=WinButton
Set Buttons=Dialog(text:=Login).ChildObjects(oButton)
TotButtons=Buttons.Count
myButton=Buttons(i).GetRoProperty(text)
myFile.WriteLine myButton
Next
myFile.Close
Set objFso=Nothing
xix) Capture Customer Names from 1 to 10 Orders in FR and export to a Text File
*****************************************************************
Test Flow:
Open the text file in write mode using File system object
Login Operation
Set objFso=CreateObject(scripting.FilesystemObject)
Set myFile=objFso.OpenTextFile(C:\NageshQtp.txt,2)
myFile.WriteLine
Dialog(Login).Activate
Dialog(Login).WinEdit(Password:).SetSecure
4c9e05a626f9b6471971fb15474e791b28cc1ed0
Dialog(Login).WinButton(OK).Click
End If
Window(Flight Reservation).Activate
Window(Flight Reservation).WinButton(Button).Click
wait 2
Next
myFile.Close
Set objFso=Nothing
xx) how to verify update Order behaviour in the Flight reservation application and how to pass
multiple values from the textfile
Option explicit
Dim fso,f,s,arr,strStatus
Set fso=CreateObject("Scripting.filesystemobject")
set f=fso.OpenTextFile("E:\Records.txt",1)
s=f.ReadLine
arr=split(s," ")
If strStatus="False" Then
Else
End If
Wend
f.Close
Set fso=nothing
xxi)How to count number of items in the Fly From Combo Box and how to display their name
one by one.
msgbox s
Next
xxii):How to display FlyFrom Combo Box items one by one into Notepad
Option explicit
Dim fso,s,x,n
Set fso=createobject("Scripting.filesystemobject")
next
s.close
xxiii)How to display Flyfrom Combo box items one by one into Runtime Data table and the
same data table export to Excel Sheet
Next
xxiv)If you select one item from Fly From Combo Box, that item should be disappeared in Fly
To Combo Box
If strcomp(x,y,0)<>0 Then
else
End If
Next
Next
xxv)How to count number of subfolders and files in a specified folder and how to display their
names one by one? Prepare script for above expected?
Option explicit Dim fso,f,sf,n,g,ft,m,k
For each g in sf
msgbox g.name
Next
For each k in ft
msgbox k.name
Next
**************************************************************************
xxvi)How to get data from one file and how set result into another file
*************************************************************************
Set objFso=Createobject("Scripting.FileSystemObject")
set f=objFso.OpenTextFile("C:\Testdata.txt",1)
objFso.CreateFolder("C:\Result")
Set f1=objFso.CreateTextFile("C:\Result\Result.txt")
s=f.ReadLine
arr=split(s," ")
t = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText()
p = Window("Flight Reservation").WinEdit("Price:").GetVisibleText()
p=mid(p,2,len(p)-1)
tot=mid(tot,2,len(tot)-1)
If cdbl(tot)=cdbl(p)*cint(t) Then
else
End If
Wend
f.Close
f1.Close
Set f=nothing
Set f1=nothing
Set objFSo=nothing
*****************************************************************************
Descriptive Programming
*****************************************************************************
Set objFlyFrom = Description.Create
'Set objwin=Description.Create
'objwin("text").value="Flight Reservation"
FlyFrom_ItemsCount = Window("text:=Flight
Reservation").WinComboBox(objFlyFrom).GetItemsCount
FlyTo_ItemsCount=Window("text:=Flight
Reservation").WinComboBox(objFlyTo).GetItemsCount
For j = 0 to FlyTo_ItemsCount-1
If strcomp(FlyFrom_Item,Window("text:=Flight
Reservation").WinComboBox(objFlyTo).GetItem(j))=0 Then
else
End If
Next
Next
*****************************************************************************