Sunday, April 17, 2011

QTP VB Script Practice Examples




Scripttoweblisttofoundtheitem
x= Input Box("enter the state")
x=browser("Register:MercuryTours").Page("Register:Mercury Tours").WebList("country").GetROProperty("Items Count")
For i=1 to x
m=browser("Register:MercuryTours").Page("Register:Mercury Tours").WebList("country").GetItem(i)
If m="INDIA" Then
MsgBox "item is found in the list:"&i+1
exit for
End If
Next
program to retirve the application validation
DataTable.ImportSheet "C:\testing.xls","sheet1","Action1"
n=DataTable.GetSheet("Action1").GetRowCount
For i=1 to n
DataTable.SetCurrentRow(i)
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
window("FlightReservation").Dialog("OpenOrder").WinEdit("Edit").SetDataTable("order","ction1")
window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
c=window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
t=window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
DataTable("cname","Action1")=c
DataTable("tickets","Action1")=t
Next
DataTable.ExportSheet "e:\data.xls","Action1"
datatable count row
DataTable.ImportSheet "C:\testing.xls","sheet1","Action1"
n=DataTable.GetSheet("Action1").GetRowCount
For i=1 to n
DataTable.SetCurrentRow(i)
Next
MsgBox n
datatable to validate the application
SystemUtil.Run"C:\ProgramFiles\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
dialog("Login").WinEdit("Agent Name:").Set DataTable("uid",1)
dialog("Login").WinEdit("Password:").Set DataTable("pwd",1)
dialog("Login").WinButton("OK").Click
If window("Flight Reservation").Exist(10) Then
window("Flight Reservation").Close
DataTable("result",1)="pass"
else
x=dialog("Login").Dialog("FlightReservations").Static("Passwordmustbeatleast").GetROProperty("text")
dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
dialog("Login").WinButton("Cancel").Click
DataTable("result",1)="fail"
DataTable("status")=x
End If
notepad data
Dim f,fs
Set fs=CreateObject("scripting.filesystemobject")
Set f=fs.CreateTextFile("C:\testing.txt")
For i=1 to 5
x=inputbox("enter the data from notepad")
f.WriteLine x
Next
f.Close
find the single method to read and write the data from
Dim f,fs,x
Set fs=CreateObject("scripting.filesystemobject")
Set f=fs.CreateTextFile("C:\testing.txt")
For i=1 to 5
x=inputbox("enter the data from notepad")
f.WriteLine x
Next
SystemUtil.Run "C:\testing.txt"
Set fs=CreateObject("scripting.filesystemobject")
Set f=fs.OpenTextFile("C:\testing.txt")
x=f.ReadAll
print x

No comments:

Post a Comment