Relevant Codes

A Test Development Resource for HP QuickTest Professional.

Recovery Scenario Test Run Error: Item in list or menu not found

October 19, 2009 · 39 comments

Recovery Operation
Creative Commons License photo credit: larryzou@

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:

Recovery Scenario Wizard

Recovery Scenario Wizard

In the window, click the following button:

Doing so will invoke the Recovery Scenario Wizard:

Recovery Scenario Wizard - Welcome

Recovery Scenario Wizard - Welcome

When the window above opens:

  1. Click Next
  2. Select Test Run Error as the Trigger Event

  3. Click Next
  4. Select ‘Test Run Error: Item in list or menu not found in the Error Listbox

  5. Click Next twice and navigate to Recovery Operation

  6. Select Function Call and Click Next

  7. Select a library which will store our Recovery Function.

  8. Select ‘Define New Function’ and in the TextArea, paste the function Recovery_ListItemIsNotFound

    Define New Function

    Define New Function

  9. Click Next
  10. Make sure ‘Add Another Recovery Scenario’ Checkbox is not selected and click Next again.

  11. Under Post-Recovery Test Run Options, select proceed to next step.

  12. Give your scenario a name and Click Next

  13. 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:

Recovery Scenario Executed

Recovery Scenario Executed

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.

{ 39 comments… read them below or add one }

1 nemo October 22, 2009 at 11:15 am

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.

Reply

2 Anshoo Arora October 22, 2009 at 9:07 pm

Thank you! I’m glad you found it useful. :)

Reply

3 Satishkumar Dega October 27, 2009 at 1:45 am

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

Reply

4 Anshoo Arora October 27, 2009 at 12:43 pm

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.

Reply

5 Satishkumar Dega November 9, 2009 at 7:15 am

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.

Reply

6 Anshoo Arora November 9, 2009 at 4:34 pm

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 :)

Reply

7 Deepak October 27, 2009 at 5:01 am

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

Reply

8 Anshoo Arora October 27, 2009 at 12:53 pm

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

Reply

9 suni October 27, 2009 at 8:19 am

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

Reply

10 Anshoo Arora October 27, 2009 at 8:55 am

Hi Suni,

How have you been?

the script wil fail again if the code depends on the selected list item which is not there in the list.

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.

Reply

11 suni October 28, 2009 at 7:43 am

Hi Anshoo,

I agree with you..we can associate recovery scenarios for any kind of scenarios as explained above ..

cheers
suni

Reply

12 Anshoo Arora October 28, 2009 at 10:05 am

Cheers, Suni :)

Reply

13 Petr November 6, 2009 at 9:15 am

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

Reply

14 Anshoo Arora November 6, 2009 at 9:40 am

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.

Reply

15 Anonymous November 6, 2009 at 1:28 pm

It makes a lot of sense as always with your articles :-)
Thank you,

Reply

16 Anshoo Arora November 6, 2009 at 3:06 pm

Thank you :)

Reply

17 Rathod November 6, 2009 at 9:35 pm

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.

Reply

18 Anshoo Arora November 6, 2009 at 9:48 pm

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.

Reply

19 Amardeep November 8, 2009 at 2:27 am

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

Reply

20 Anshoo Arora November 8, 2009 at 9:16 pm

I’m glad it helped you, Amardeep. Thank you.

Reply

21 Syed November 17, 2009 at 9:30 am

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

Reply

22 Anshoo Arora November 17, 2009 at 9:58 am

Thank you, Syed! I’m glad it helped.

Reply

23 RAJ December 1, 2009 at 4:35 am

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.

Reply

24 Anshoo Arora December 1, 2009 at 6:10 pm

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..

Reply

25 testking December 2, 2009 at 12:14 am

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

Reply

26 Anshoo Arora December 2, 2009 at 11:17 am

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 :)

Reply

27 Ramesh December 2, 2009 at 11:14 am

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.

Reply

28 Anshoo Arora December 2, 2009 at 11:18 am

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.

Reply

29 Ramesh December 2, 2009 at 11:44 am

I asked this same question in SQAforums.com :)

Reply

30 Anshoo Arora December 2, 2009 at 5:26 pm

I was wondering if that was you on SQAForums. :)

Reply

31 Stefan December 23, 2009 at 4:11 am

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!

Reply

32 Anshoo Arora January 1, 2010 at 3:22 am

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.

Reply

33 Bhavi January 6, 2010 at 11:56 am

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!

Reply

34 Anshoo Arora January 7, 2010 at 4:03 am

Thank you! I’m glad you found the content on RelevantCodes helpful. :)

Reply

35 Venkat February 26, 2010 at 12:55 am

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’

Reply

36 Anshoo Arora February 28, 2010 at 5:54 pm

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?

. 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).

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..

One more doubt is how does ‘recovery scenarios’ differ from the ‘When error occurs during run session: Proceed to next step’

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.

Reply

37 Venkat March 2, 2010 at 5:22 am

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

Reply

38 Anshoo Arora March 2, 2010 at 4:28 pm

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..

Reply

39 Lohith March 9, 2010 at 11:47 pm

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

Reply

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Previous post:

Next post: