Automating QTP Test Automation Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map
Error Handling in QTP
Other people have written some really good articles on this. The best I have found so far is this one by Dani Vainstein To summarise the use of the 'Recovery Scenario' in QTP I am best quoting Theo Moore: '...I can honestly say that they blow...and I mean goats...nickel a herd...' (I'm not familiar with that saying, but I'm guessing it isn't complimentary). As a general rule you should write all the error handling code yourself so that your tests can fail gracefully and enable your test suites to be fault-tolerant. That old, but much touted example scenario of a printer running out of paper is a really bad example. And how often does providing the option of 'retry' or 'skip' actually resolve anything? So, how to write your own error handling? - first a short history lesson... History vbScript is based on VB (visual basic) which in turn is based on GW-Basic and QuickBasic
Basic used to use line numbers for flow control
(It was an undocumented feature of Visual Basic that it still supported line numbers
Consequently the normal way to invoke error handling was 'On Error GoTo Xxx' You would then put your error handling in the area following the line label. Error handling was then turned off using the command 'On Error GoTo 0'. This history explains the current way of turning off error handling! Unfortunately, line labels and 'Goto' do not exist in vbScript. This means that the ONLY way to fully implement your own error handling is to check the Error object status immediately after EVERY line of code! NOBODY wants to do that That's why people use the Recovery Scenario mechanism. A New Approach Years ago, when I was working on a large project using VB3 and around 30 developers, I wrote a handy tool to completely automate the addition of the error handling code to the vb source code. I have now written a similar tool for QTP This only works for script files NOT test files (but then most of your code should be in scripts). Anyway, give it a try and let me know what you think. You can find it here. |