Recovery Scenarios or handle most of them in the functions itself
There are few scenarios which i can expect during my execution, I would like to 开发者_运维百科understand the best practices of handles such run time errors.
One more question, is it worth to load all the recovery scenarios during the load of the functions or handle the exception with in the functions itself.
Kindly suggest the best practices and why you suggest we need to go for that.
In my experience with QTP, it's best to handle known exception scenarios directly in your functions, and leave the exception handling mechanism for unknown or unexpected exceptions. Recovery scenarios use additional machine resources and can slow down your tests, so only use them in a limited fashion for catching truly exceptional scenarios.
Due to naming established in QTP, beginners often confuse exceptions and GUI events.
Truly, pop-up window is not an "exception" even if it "crashes" script execution.
For catching and recovery from failed operations, I recommend using "On Error Resume Next...On Error GoTo 0" statements.
For catching GUI events, that may or may not happen, you can use QTP Recovery Scenarios, BUT, as Tom E mentioned, each activated recovery handler uses extra resources and affects QTP performance.
Best way to use only those of them you would need, and keep the rest deactivated.
A few examples.
1.Catching exceptions
This way, if you have RegEx syntax errors, execution won't stop.
Set objRegEx = New RegExp
objRegEx.Pattern = strRegEx
On Error Resume Next
boolRC = objRegEx.Test(strSrc)
intRC = Err.Number
On Error GoTo 0
If intRC <> 0 Then boolRC = False
Set objRegEx = Nothing
2.Dynamically operating Recovery handlers
intPos = Recovery.GetScenarioPosition("API\Exceptions\AppExceptions.qrs", "Recovery_on_Error1")
''# You can store intPos (position in QTP's qrs file) for all handlers during initialization
Recovery.SetScenarioStatus intPos, boolState ''# Parameterize boolState as True or False
''# Enable or disable handlers this way. Disabled handler does not consume QTP resources.
Thank you,
Albert Gareev
http://automation-beyond.com/
精彩评论