Wednesday, December 29, 2010

QTP- Sample Code for On Error Resume Next

'Code for On Error Resume Next
Option Explicit
Dim str,pos
On Error Resume Next
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "Ram" @@ hightlight id_;_329434_;_script infofile_;_ZIP::ssf1.xml_;_
wait 1
Dialog("Login").WinEdit("Agent Name:").Type  micTab  @@ hightlight id_;_329434_;_script infofile_;_ZIP::ssf2.xml_;_
Dialog("Login").WinEdit("Password:").SetSecure "70c2099ae893a36408d79e83975" @@ hightlight id_;_263888_;_script infofile_;_ZIP::ssf3.xml_;_
wait 1
Dialog("Login").WinEdit("Password:").Type  micTab  @@ hightlight id_;_263888_;_script infofile_;_ZIP::ssf4.xml_;_
Dialog("Login").WinButton("OK").Type  micReturn  @@ hightlight id_;_263902_;_script infofile_;_ZIP::ssf5.xml_;_
window("text:=Flight Reservation").Close
Msgbox Err.Number&"       :     "&Err.Description
If (err.Number<>0) Then
 str=dialog("Login").Dialog("Flight Reservations").GetVisibleText( )
 pos=Instr(1,str,"Agent name",VBTextCompare)
   If (pos<>0) Then
     Call Edit_Agent("Rama")
     Else
     Call Edit_Password("mercury")
   End If
End If
Public Function Edit_Agent(ag)
   Dialog("Login").Dialog("Flight Reservations").Close
   dialog("Login").WinEdit("Agent Name:").Set ag
   dialog("Login").WinButton("OK").Click
   window("text:=Flight Reservation").Close
   Err.Clear
   Err.Close
End Function
Public Function Edit_Password(pwd)
   Dialog("Login").Dialog("Flight Reservations").Close
   dialog("Login").WinEdit("Password:").Set pwd
   dialog("Login").WinButton("OK").Click
   window("text:=Flight Reservation").Close
   Err.Clear
   Err.Close
End Function
'****************************************************************

No comments:

Post a Comment