Here are two examples:
script extract:
1)
'Subroutine is called for all failure code.
Sub Failure(target$, id$, OP_REF$, message$)
errormsg$= TargetAppName$ + ": " + message$ + " during step: " + target$ + ". " + OP_REF$
nimQoSStop()
nimQoSSendNull(target$)
nimAlarm(4, errormsg$, target$, id$) '*****Uncomment this line to enable alarming*****
nimEnd()
MsgFrame(errormsg$, 1)
Print_Screen()
RemoveFrame(1)
Clean_Up()
EndSub
2) Examples within a full script
Include "NimBUS-functions.src"
Sub Clean_up()
KillApp("IEXPLORE.EXE",1)
EndSub
'Below is a generic error handling routine
Sub Process_Error()
local buffer$
'If within this proc, an error occurs too, it generates an infinite loop as
'the call to the error proce causes an error. To avoid that, we disable OnAction Error within this proc.
disable(Error)
'Take a screenshot of the desktop
file_path$="C:\"+#ErrorScript$+"_error"
ret=Hardcopy(file_path$+".jpg",1,1)
'Here a part for writing in a txt file where we were in the script, the error code, the error message when the error occurred.
buffer$="------ "+Date$()+ " - "+Time$()+" -------"
write(file_path$+".txt",buffer$,crlf)
buffer$="Error in : "+#ErrorScript$
write(file_path$+".txt",buffer$,crlf)
buffer$="Error line : "+str$(#LastErrorLine)
write(file_path$+".txt",buffer$,crlf)
buffer$="Error Code : "+str$(#Errorcode)
write(file_path$+".txt",buffer$,crlf)
buffer$="Error Function : "+#ErrorFunction$
write(file_path$+".txt",buffer$,crlf)
buffer$="Error message : "+#ErrorMsg$
write(file_path$+".txt",buffer$,crlf)
'Add here other lines for what to do in case of an error.
'......
nimQoSStop() 'Stops the QoS timer.
nimQoSSendNull(target$) 'Send the response time measurement- timeout value per customer
nimSetVariable("suppression_id",#ErrorScript$+"-Script error")
nimAlarmSimple (5,"Error in : "+#ErrorScript$+" at line : "+str$(#LastErrorLine)+" Error Function: "+#ErrorFunction$+"Error message : "+#ErrorMsg$) ' Sends a major alert that the script did not run. The number 5 is critical 4 is major, etc
nimEnd()
Clean_up()
End
Endsub
OnAction error
dosub Process_Error
endaction
#PauseTimeout = 30 'Default for Pause until statements is a 2 minute/120 secs timeout
#HideTrayIcon = 1
'#ActionTimeout= 10 'The default value for #ActionTimeout is 30 seconds
#IgnoreErrors = 1 'This is required to use a custom error handling routine
#SendKeysDelay = 3
niminit()
nimSetVariable("subsystem", "MSPetSHop")
target$= "MSPetShop-Launch 1"
nimSetVariable("suppression_id", target$)
nimQOSStart()
StartBrowser("IE", "http://localhost/Default.aspx",3)
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|Welcome to .NET Pet Shop - Microsoft Internet Explorer",1)
PauseFalse
nimAlarmSimple(4, "MSPetShop-Launch failed")
nimQOSStop()
nimQOSSendNull(target$)
nimend()
Clean_up()
End
EndPause
nimAlarmSimple(0, "MSPetShop-Launch succeeded")
nimQOSStop()
nimQOSSendTimer(target$)
target$= "MSPetShop-Login 2"
nimSetVariable("suppression_id", target$)
nimQOSStart()
UsePage("Welcome to .NET Pet Shop")
ClickHTMLElement("A[INNERTEXT= 'sign in']")
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Sign In - Microsoft Internet Explorer",1)
PauseFalse
nimAlarmSimple(4, "MSPetShop-Login: Sign in page failed to load")
nimQOSStop()
nimQOSSendNull(target$)
nimend()
Clean_up()
End
EndPause
nimAlarmSimple(0, "MSPetShop-Login: Sign in page success")
'Read in a single encrypted password to use for login
file$ = "password_encrypt.txt"
Read(file$,pwd$,CRLF) ' puts the first line of file$ in pwd$
UsePage(".NET Pet Shop :: Sign In")
WriteHTML("INPUT TEXT[NAME= 'ctl00$cphPage$Login$']", "RobYoung")
WriteHTMLEncrypted("INPUT PASSWORD[NAME= 'ctl00$cphPage$Login$']", pwd$)
ClickHTMLElement("INPUT SUBMIT[VALUE= 'Sign In']")
PAUSE 10 secs until
Bitmap("C:\Program Files\NimBUS\e2e_scripting\Scripts\demo_sign_out.bmp")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|Welcome to .NET Pet Shop - Microsoft Internet Explorer|1",1)
InArea( 705, 3, 202, 388 )
PauseFalse
nimAlarmSimple(4, "MSPetShop-Login: Failed")
nimQOSStop()
nimQOSSendNull(target$)
nimend()
Clean_up()
End
EndPause
nimAlarmSimple(0, "MSPetShop-Login: Success")
nimQOSStop()
nimQOSSendTimer(target$)
UsePage("Welcome to .NET Pet Shop")
ClickHTMLElement("A[INNERTEXT= 'Endangered']")
PAUSE until
Bitmap("C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_skeleton_pic.bmp")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Endangered - Microsoft Internet Explorer|1",1)
InArea( 369, 184, 182, 219 )
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UseWindow( "IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Endangered - Microsoft Internet Explorer|1",1 )
ClickOnBitmap( "C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_Pet.bmp", left, single,
InArea( 384, 282, 208, 162 ) )
PAUSE until
Bitmap("C:\Program Files\NimBUS\e2e_scripting\scripts\MSPetShop_rover.bmp")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Pet - Microsoft Internet Explorer|1",1)
InArea( 366, 170, 296, 363 )
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Pet")
ClickHTMLElement("A[INNERTEXT= 'Add to Shopping Cart']")
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Shopping Cart")
ClickHTMLElement("A[INNERTEXT= 'Continue Shopping']")
PAUSE until
Bitmap("C:\Program Files\NimBUS\e2e_scripting\Scripts\MSPetShop_rover.bmp")
InWindow("IEXPLORE.EXE|Internet Explorer_Server|.NET Pet Shop :: Pet - Microsoft Internet Explorer|1",1)
InArea( 366, 170, 296, 363 )
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Pet")
ClickHTMLElement("A[INNERTEXT= '< Back to list']")
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Endangered - Microsoft Internet Explorer",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Endangered")
ClickHTMLElement("A[HREF= 'http://localhost/Items.aspx?p']")
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Skeleton - Microsoft Internet Explorer",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Skeleton")
ClickHTMLElement("A[INNERTEXT= 'Add to Shopping Cart']")
Pause until
WinStatus(Active)
InWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
PauseFalse
MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
End
EndPause
UsePage(".NET Pet Shop :: Shopping Cart")
ClickHTMLElement("INPUT IMAGE[NAME= 'ctl00$cphPage$Shoppi']")
ClickHTMLElement("INPUT IMAGE[NAME= 'ctl00$cphPage$Shoppi']")
ClickHTMLElement("A[INNERTEXT= 'sign out']")
UseWindow("IEXPLORE.EXE|IEFrame|.NET Pet Shop :: Shopping Cart - Microsoft Internet Explorer",1)
Sendkeys("<Alt> f")
Sendkeys("c")
nimEnd()