May 11, 2011

Curious QTP behaviour when using on error: Proceed to Next Step

Because we build our own framework, the on error settings in QTP are default on "Proceed to Next Step" for our unattended continuous script. So when a test is scheduled in the middle of the night, the test won't stall on errors like a function with an argument too few or many, an array that is out of bounds or an accidentally undeclared variable (please build an undeclared variable checker HP, the Patterson boys could do it years ago, you can do it too!).

It works fine most of the time, although debugging is done with an "attended run" script and all possible error detection on: Popup Messagebox and Option Explicit everywhere.

The curious behaviour happened in an Select Case. Consider this code:

Option Explicit
Dim myCondition : myCondition = 2
Select Case myCondition
    Case 1 MsgBox "Wooh! Condition 1"
    Case 2 MsgBox "Displaying undeclared variable: " & undeclaredVariable
    Case 3 MsgBox "Meh, Condition 3"
End Select 

When you run this code in attended mode, you'll get a nice error nagging about the undeclared variable.
However, when you run this in unattended mode, you'll get a messagebox with the text: "Meh, condition 3"

QTP is doing what it says: Continue with the next step. But the step is not fulfilling the Select condition and program technical a major sin!
Because I ran this accidentally in unattended mode, it took me some while to get a finger behind the error. In the end, I learned to always debug in attended mode.

3 comments:

Boyd Patterson said...

Thank you for the reference to our tool, Test Design Studio. You mentioned a few other common errors (like incorrect number of arguments for a function), so I wanted to mention that our static code analysis checks for that as well.

The following page discusses all of the code quality aspects of our tool:

http://www.patterson-consulting.net/products/test_design_studio/CodeQuality.aspx

Hari Sreekanth Upadrasta said...

This is not only the case with select case but will apply for all the conditional/looping statements as well. I faced a similar situation some time before.
http://bughunterz.blogspot.com/2009/09/when-not-to-place-positive-condition-in.html

QPT said...

Useful article.
QTPbook