Handling script errors

QA Wizard Pro provides two ways to handle errors that occur when running scripts:

You can use inline and structured error handling together, but typically you only use one method per script. Consider using structured error handling in scripts that require advanced error responses. The Finally statement can be used to perform script maintenance whether or not errors are encountered.

The following example shows structured error handling used to add information to an output file, perform various checkpoints, and indicate the end of the output log. The Try...Catch...Finally statements allow the errors to be logged while ensuring the output log is correct and complete.

AppendToFile("C:\\Testing\\Output.txt", "Starting checks")

Try

Window("Login").Button("btnLogin").Checkpoint("Text", "Login", True, "Login button text is incorrect")

Window("Login").Button("btnCancel").Checkpoint("Text", "Cancel", True, "Cancel button text is incorrect")

Window("Login").Button("btnHelp").Checkpoint("Text", "Help", True, "Help button text is incorrect")

AppendToFile("C:\\Testing\\Output.txt", "All checks complete")

Catch

AppendToFile("C:\\Testing\\Output.txt", "Checkpoint failure: " + Err.Description())

Finally

AppendToFile("C:\\Testing\\Output.txt", "Finished checks")

End Try

Consider using inline error handling if you have a script that calls other scripts and you want playback to continue even if errors are encountered in the called scripts.

The following example shows a controller script that launches several other scripts. The On Error Resume Next statement ensures each script runs even if one or more of the called scripts fails.

On Error Resume Next

Script.CallScript("MenuCheck")

Script.CallScript("LoginChecks")

Script.CallScript("ShoppingcartChecks")

Script.CallScript("OrderStatusChecks")

On Error Goto 0