QTP Scripting Examples
'Count Lines in a Text File
Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents and Settings\Administrator\Desktop\qtpthiru.txt")
While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
objTextstream.ReadLine
Wend
Msgbox LineCount
objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing
'Read a Text File from 4th line and perform Data Driven Testing for Login operation
Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents and Settings\Administrator\Desktop\qtpthiru.txt")
While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
objTextstream.ReadLine
Wend
Msgbox LineCount
objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing
'Read a Text File from 4th line and perform Data Driven Testing for Login operation
Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents andSettings\Administrator\Desktop\qtpthiru.txt")
While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
myLine=objTextstream.ReadLine
If LineCount >= 4 Then
myField=Split(myLine,",")
SystemUtil.Run "C:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTestProfessional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set myField(0)
Dialog("Login").WinEdit("Password:").Set myField(1)
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End If
Wend
objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing
'Read a Text File from 4th line to 6th Line and perform Data Driven Testing for Login operation
Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents and Settings\Administrator\Desktop\qtpthiru.txt")
While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
myLine=objTextstream.ReadLine
If LineCount >= 4 and LineCount<=6 Then
myField=Split(myLine,",")
SystemUtil.Run "C:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTestProfessional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set myField(0)
Dialog("Login").WinEdit("Password:").Set myField(1)
Wait 2
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
End If
Wend
objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing
'Open 1 to 10 Orders in Flight Reservation Application and export all fields to excel file (3rd sheet)
Dim objExcel, objWorkbook, objWorksheet
Set objExcel=CreateObject("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Open("C:\Documents andSettings\Administrator\Desktop\qtpthiru.xls")
Set objWorksheet=objWorkbook.Worksheets(3)
objWorksheet.Cells(1,1)="OrderNo"
objWorksheet.Cells(1,2)="Date of Flight"
objWorksheet.Cells(1,3)="Fly From"
objWorksheet.Cells(1,4)="Fly To"
objWorksheet.Cells(1,5)="C_Name"
objWorksheet.Cells(1,6)="Tickets"
For i= 1 to 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
objWorksheet.Cells(i+1,1)=i
Wait 1
objWorksheet.Cells(i+1,2)= Window("Flight Reservation").WinObject("Date of Flight:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,3) = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,4)= Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,5) = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,6) = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing
'Open 1 to 10 Orders in Flight Reservation Application and export all fields to excel file (3rd sheet)
Dim objExcel, objWorkbook, objWorksheet
Set objExcel=CreateObject("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Open("C:\Documents andSettings\Administrator\Desktop\qtpthiru.xls")
Set objWorksheet=objWorkbook.Worksheets(3)
objWorksheet.Cells(1,1)="OrderNo"
objWorksheet.Cells(1,2)="Date of Flight"
objWorksheet.Cells(1,3)="Fly From"
objWorksheet.Cells(1,4)="Fly To"
objWorksheet.Cells(1,5)="C_Name"
objWorksheet.Cells(1,6)="Tickets"
For i= 1 to 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
objWorksheet.Cells(i+1,1)=i
Wait 1
objWorksheet.Cells(i+1,2)= Window("Flight Reservation").WinObject("Date of Flight:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,3) = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,4)= Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,5) = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
Wait 1
objWorksheet.Cells(i+1,6) = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing
0 comments:
Post a Comment