views:

1516

answers:

1

I'm implementing an extension to QTP using the Web Extensibility Toolkit. If my JScript function that implements the QTP action encounters an error (e.g User gave wrong argument values), I want the QTP to stop the test execution and notify the user about the error. I want it to act as a normal error in QTP and ask if the user want to debug\retry\skip\stop execution.

How can I do it?

+1  A: 

If you throw an exception with a string then the message you throw is presented in QTP like any other script error (StopRetrySkipDebug)

throw "I'm sorry, Dave. I'm afraid I can't do that";

However from trying it out it looks like this only works with string literals, if you concatenate a literal with a variable it shows only the literal part:

throw "I'm sorry, Dave. I'm afraid I can't do " + param;

QTP displays:

I'm sorry, Dave. I'm afraid I can't do

When using a string variable:

var msg = "I'm sorry, Dave. I'm afraid I can't do " + param;
throw msg;

QTP displays (X's to protect the guilty):

An error occurred while running the Web extensibility handler for the 'Xxx' method Error details:

File: c:\qtp\dat\extensibility\web\toolkits\xxx\xxx.js

Line: 51

Description: Exception thrown and not caught

Motti
When I tried it, I got a message in the explorer saying that: An exception was thrown and not caught. Asking me if I want to debug it.After pressing no, I get the desired QTP message but the error description is still "An exception was thrown and not caught".
Eldad
The exception from explorer is because you don't have `Disable script debugging (Internet Exploere)` checked (from `Tools -> Internet Options -> Advanced`) which is the recommended mode when working with QTP.
Motti
With string variables (var e = "error"; throw e;), the whole JS file is not working.With String literals (throw "error";) I still get the same:Description: Exception thrown and not caught
Eldad
That's strange, try it with `throw "error";` as the only thing on that specific script line (it works for me).
Motti