tom
tom

Reputation: 1223

Getting error information when executing recovery scenario

First what I need to accomplish... If the test fails it leaves a web browser open and I need to close it. I cannot just close iexplore.exe as there might be other browser windows opened that I want to leave opened.

Now... I have a recovery scenario that fires on any error in test execution where I close the specific browser window. When the test fails it fires up and closes the browser. Excellent. The problem is that the test is marked as passed. I can fail it using reporter.reportevent, but I still miss the data about the error.

If I disable the recovery scenario the test fails, correctly, and I have a bunch of information about why the test failed. Is it possible to have that information passed to the recovery scenario? So I could close the browser, fail the test AND have the information about the problem.

Upvotes: 2

Views: 693

Answers (1)

Trimble Epic
Trimble Epic

Reputation: 466

It really depends on how your test is failing. Recovery Scenarios are great for handling completely unpredictable situations - like the browser window completely crashing at an unpredictable time, or the network connecting dropping for whatever reason, or worse, some nag screen appears offering to upgrade you to the latest operating system and takes over the screen...

If your script is failing at a predictable point, such that you can sprinkle in IF statements that check to make sure your next step is viable (i.e. check if button.exists), then you don't need to rely on the recovery scenario - you would start the fail test process directly.

Here's what I do - I have a function called FailTestBecause() that takes one parameter - a string containing the reason for failure (I know the reason because of the if statement that wraps the call to this function)

FailTestBecause() first sets a flag indicating failure, logs the failure message to reporter, the log, and to my own error file, then attempt to fire an action called "Finish Test". If action: Finish Test doesn't exist, then gracefully exits using Exittest().

FinishTest is the last action in my test, and when it starts, it checks for the error flag. either way, it's job is to upload any remaining files back to QC/ALM. This way, I always get my test data gathered up and uploaded to QC before the script actually stops.

My code is liberally sprinkled with failure checks. here's an example...

Browser("Trade").Page("Login Page").WebEdit("User ID").Set User_ID
Browser("Trade").Page("Login Page").WebEdit("Password").SetSecure User_Password
Browser("Trade").Page("Login Page").WebButton("Login").Click

Do Until Browser("Trade").Page("Main Page").Exist(0)
  If Browser("Trade").Page("Login Page").WebElement("Login Failed").Exist(0) then 
    FailTestBecause "Login Failed, user credentials didn't work"
  ElseIf Browser("Trade").Page("Challenge Questions").Exist(0) then
    say "Found Challenge Questions Screen, handling it..."
    RunAction "Handle Challenge Questions", OneIteration
  ElseIF Browser("Trade").Page("Create Password").Exist(0) then
    FailTestBecause "Detected new password, requires manual change"
  ElseIf not Browser("Trade").Exist(0) then
    FailTestBecause "Browser page crashed?"
  Else
    FailTestBecause "Something (unhandled) went wrong, please review log"
  End If
Loop

Check for failure often. We are testers, after all.

Upvotes: 1

Related Questions