Automated tests are created mainly to be run unattended, and this raises a few concerns for automation developers. Assume a situation where you initiated your test-suite while leaving your office to be run over-night. However, because of unforeseen errors, your test stops at a point and disrupts your results. When you return to your desk the next day, only to find that your tests aren’t completely executed. This can be quite frustrating, and its crucial to be proactive and handle such errors before they impact your work.
This article discusses a way of creating a Recovery Scenario for an instance where an item in the list item or menu is not found.
In this example, we will define a Function Call and use that Function Call to handle the error. The default syntax for the Recovery Scenario Function is:
Function fnRecovery(Object, Method, Arguments, retVal) 'Error Handling Code End Function
Explanation of each argument to fnRecovery is given below:
Object as Object: The object of the current step. Method as String: The method of the current step. Arguments as Array: The actual method's arguments. Result as Integer: The actual method's result.
To handle this scenario, we will use the function below:
Function Recovery_ListItemIsNotFound(Object, Method, Arguments, retVal) Dim sAllItems, arrAllItems, intItem With Object 'Retrieve all items from the Listbox sAllItems = .GetROProperty("all items") 'Split 'all items' using a delimiter ";" into an array arrAllItems = Split(sAllItems, ";") 'Select a random number intItem = RandomNumber.Value(LBound(arrAllItems), UBound(arrAllItems)) .Select "#" & intItem Reporter.ReportEvent micInfo, "ListItemIsNotFound", "Item: " & .GetROProperty("value") End With End Function
Recovery_ListItemIsNotFound, as the same suggests, executes the Recovery Operation if the list item that we supplied to our target WebList does not exist. This is quite common in Web applications, and Items in a WebList can change depending upon the input(s) provided.
To start, Click Resources -> Recovery Scenario Manager. You should see a window like this:
In the window, click the following button:
Doing so will invoke the Recovery Scenario Wizard:
When the window above opens:
- Click Next
- Select Test Run Error as the Trigger Event
- Click Next
- Select ‘Test Run Error: Item in list or menu not found in the Error Listbox
- Click Next twice and navigate to Recovery Operation
- Select Function Call and Click Next
- Select a library which will store our Recovery Function.
- Select ‘Define New Function’ and in the TextArea, paste the function Recovery_ListItemIsNotFound
- Click Next
- Make sure ‘Add Another Recovery Scenario’ Checkbox is not selected and click Next again.
- Under Post-Recovery Test Run Options, select proceed to next step.
- Give your scenario a name and Click Next
- And finally, Check the following option: Add Scenario to current test and Click Finish. Save Changes before closing.
We will use the WebList below to select a value that does not exist in it; so, let’s write a code to select Rational Robot. If you view the items present in the listbox, you will notice that Rational Robot indeed doesn’t exist, but our Recovery Scenario will handle the error when we select it. Instead, it will select a random value from the list.
Browser("title:=.*Recovery Scenario.*").Page("micclass:=Page")_ .WebList("name:=testTools").Select "Rational Robot" MsgBox "Item Selected: " & Browser("title:=.*Recovery Scenario.*").Page("micclass:=Page")_ .WebList("name:=testTools").GetROProperty("value")
When the code above executes, you will notice that, instead of throwing a Test Run Error, a random value from the list box was selected. You will know that the Recovery Scenario was triggered and ran successfully when you view the Test Results:
There are plenty of other scenarios as well, and I will try to cover some of the important ones. If you have any suggestions, or a scenario that you would like me to cover first, please use the comments section of this post to share your ideas/thoughts with me. Thanks! :)
If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.

FaceBook
LinkedIn
Twitter
YouTube
{ 39 comments… read them below or add one }
Good example.I found it very helpful.Especially the time you took to explain it step by step by inserting screen shots.
Thanks a lot.
Thank you! I’m glad you found it useful. :)
Hi Anshoo,
I appreciate the work being done by you for the QuickTest newbie’s.Anshoo,as a member of AdvancedQTP forum, your solutions for the queries are very simple and easily understandable even for the newcomers. Great Job!
I am strated to learn QTP in my own way could please help me regrading below topics with screen shots or any vedio that is good for me.
please give me one real time example in using Inputparmeters and out put parameters in QTP and aslo explain the using mutiple action using those things I need step by step explanation could u please provide a soluation
Sure, Satish. I will try my best to help you. I don’t use QTP’s inbuilt parameters much, so I am not sure how good I will be able to explain it but I will try to write an article in the coming few days. Thanks.
Hi Anshoo,
could please give me one real time example in using Inputparmeters and out put parameters in QTP and aslo explain the using mutiple action using those things I need step by step explanation could u please provide a soluation.
Hi Satish,
I rarely use Input/Output parameters and my knowledge about this is quite rusty. However, I will try to post something about them in the near future.
Thanks :)
Hi Anshoo,
i like ur articles a lot informative and wants some detailed information on Keyword driven framework and howz it can be implemented
Regards
Deepak
Hi Deepak,
Its quite hard to sum up the concepts and complexities of any sort of a framework that easily. However, you can find some information on Keyword-driven Testing here. Also, I would recommend you to visit AdvancedQTP’s KnowledgeBase and download FramworkManager. I’m sure these 2 sources will provide you ample information to begin with. If you have any questions in the meantime, please post here and I will try my best to help you.
PS. You should really check out FrameworkManager.
Thanks- Anshoo
Hi Anshoo,
The usage of recovery Scenario is explained very clearly…the script wil fail again if the code depends on the selected list item which is not there in the list.Hence we run the suite that checks the master data first and then the main suite…
thanks
suni
Hi Suni,
How have you been?
Absolutely correct. However, if the script encounters such error again, it will trigger the Recovery Scenario (again). In other words, unlike our normal code which is Single Threaded, Recovery Scenarios work more like a Try…Catch mechanism.
Hi Anshoo,
I agree with you..we can associate recovery scenarios for any kind of scenarios as explained above ..
cheers
suni
Cheers, Suni :)
Hi Anshoo,
I like your articles a lot. Thank you for your effort to propagate the knowledge.
I have a question about Error Handling in QTP scripts. Do you ever use “On Error Resume Next” construct in your scripts? I look through most of your articles and cannot find any info on it. What do you think about it?
Thank you,
Petr
Excellent question, Petr.
Actually, I do use “On Error Resume Next” quite a bit. However, you do not see a lot of it in my articles because I feel its not an efficient way to handle errors, and even though I know people use it, I try not to reinforce its use :)
When the deadlines are tight and the pressure builds up, I feel I use it more then as compared to when things are going quite smooth, which gives me more time to make my code robust. I have a few functions that do a lot of error handling with simple Conditional Blocks, but a lot of my core code in my framework runs within On Error Resume Next statements.
Also, in short, the more generic my framework, the greater the use of it. However, that also means, it can become very difficult to catch an error which you would easily find, without its use.
It makes a lot of sense as always with your articles :-)
Thank you,
Thank you :)
Hi Anshoo ,
I am new to qtp and until now i just know only tht pop up recovery scenario.Thank you very much for your time to prepare detailed description of this recovery scenario.This is defiantly very useful to everyone working on qtp.
One thing for me is not clear.Why are you selecting the item which is not in the list? When the item is not in the list why to select it?
Can you explain me where exactly we need to use this recovery scenario.
Hi Rathod,
Actually, this post is just a demo of how a function call can help in such situations with Recovery Scenarios. In reality though, the example stated in this post is a complete possibility.
Let’s suppose you are creating an automated test for a Checkout process of a Shirt. The test case says that you would Checkout an Orange color shirt for size “L”. In the selection list, generally there are 4 sizes: S, M, L, XL.
However, for an Orange Color shirt, only sizes “M” and “XL” are left. Sizes “S” and “L” are all sold out.
Now, your script runs and tries to find and select size “L” from the listbox. But, as we mentioned above that size “L” does not exist. Because of this dynamic behavior of the application, QTP will still try to select item “L” (which is not there). Instead, it will throw a run error and cause the script to halt.
However, because we have created this Recovery Scenario, it will choose either size “M” or “XL”, and move on. In other words, it will save us from something we did not expect – which is the core concept of a Recovery Scenario.
Hi Anshoo,
I was just looking the kind of example to better understand the rs.You have Wonderfully explained the concept with relevant yet simple to understand example.Keep it up.Thanks a lot.
Regards
Amardeep
I’m glad it helped you, Amardeep. Thank you.
Thanks a lot Anshoo Arora. this code will simplify my life of constant error messages i receive due to object not found in the items list.
Thanks,
Syed
Thank you, Syed! I’m glad it helped.
I created around 20 QTP scripts. While creating them i didn’t know about recovery scence.
Know I created one Recovery Scenario, but I want it to applicable to all earliar 20 sceipts.
How can I do this.
Pease help me.
Hi Raj,
There are 2 ways this can be done:
1. Use AOM to associate your Recovery Scenarios with Tests. See here. The only way you can add Recovery Scenarios programatically is through an external VBS file as demonstrated in the link at SQAForums.
2. Manually associate them..
Hi Anushoo,
One of my friend said creating recovery scenario will eat time and will lead to performance issue??? How far it is true. Guide me Anshoo.
Thanks
This may be true, but I have never tested the performance of my scripts with and without the Recovery Scenarios I use, so, I can’t be entirely sure of this. I think a little bit of performance impact is not a problem as long as my Recovery Scenarios are bridging the gap between the bugs I create in my code :)
I am using QTP 9.2. After I clicked Resources -> Recovery Scenario Manager, Recovery Scenario window is displayed. And in this window the “New” button on the does not work. Hope you noticed it. I don’t know if they fixed it QTP 10 version.
Ramesh,
You’re absolutely correct, and this is the same in QTP 9.5 as well. I’m not sure that that button is supposed to do, since there is a seperate buttom right underneath it to create a new scenario.
I asked this same question in SQAforums.com :)
I was wondering if that was you on SQAForums. :)
By the way, finding/selecting an list item is especially a problem with QTP 10 and doesn’t work with SAPList objects:
Browser(“ABC”).Page(“ABC”).Frame(“ABC”).SAPList(“001″).Select “04″
and the error message is cannot identify 04 element of SAP List 001. Check if it is available in list of all elements.
I haven’t found any solution, maybe someone else has a workaround or helpful answer fixing that problem.
Thanks in advance!
Hi Stefan,
I haven’t had a chance to work with SAP, but I hope someone reading this comment section may be able to help. Consequently, you can even refer to one of the forums to have your query answered.
Hi Anshoo,
When i start browsing your blog my time pass so fast and you have so good examples, solution where i do suggesting my jr.qa to your blog.Thanks so much and all the information so helpful.
Thanks,
Princess!
Thank you! I’m glad you found the content on RelevantCodes helpful. :)
Hi Anshu,
I appreciate your interest in responding to the questions and your articles too….
I have a small doubt based on recovery scenarios. Here is the brief demonstration of it.
I have a piece of code which causes my script to fail (as it is known issue… I cant handle this through the script(constraint) ) I have written a recovery scenario(RS1) and it triggered properly when any error arises. Later I enhanced my script to capture my error which QTP throws during run time and depending on the error I want script to trigger recovery scenario (RS2). Is that possible …? (I have associated both the recoveries to the test…What I observed is it is running both the recovery scenarios whenever any error arises in the script).
One more doubt is how does ‘recovery scenarios’ differ from the ‘When error occurs during run session: Proceed to next step’
One question: If you can’t handle it through your script, how can you handle it through your Recovery Scenario? Wouldn’t the same code be applied in the situation where this constraint occurs?
It may be. I am going to do some research on this and get back to you, but my initial thought would be that this might just be possible..
When error occurs during run session: Proceed to next step is a subset of Recovery Scenarios. A Recovery Scenario has the functionality to let users to proceed to the next step when their core-recovery-scenario-action is performed.
Hi Anshu,
I can handle the script by modifying it (which is a hectic problem for me..I just want my existing scripts not to be modified but want them to be handled through recovery scenarios…). So I tried in this track for a better solution and found few problems which I have mentioned in my earlier post.
Thanks,
Venkat
Gotcha. I will try do some research on this and post my observations here. But, technically, what you’re trying to do should be possible..
How to parameterise the Recovery Scenario files into the Driver Script?
How to redirect the Test Result to the Excel sheet?
Please let me know at the earliest….
Thanks,
-Lohith