Why does `IsEmpty` write a dummy warning when called with a test object while a recovery scenario is active?

StackOverflow https://stackoverflow.com/questions/21730474

  •  10-10-2022
  •  | 
  •  

Question

Very strange symptom:

Create a test with the following content and no associated libraries:

Print IsEmpty (Browser("index:=0"))

The point is to call IsEmpty with any test object.

Result when executed: The obvious (and expected), it prints: "false" (provides you have at least one window open on your desktop).

Run result looks fine in the viewer, like this:

Run result as expected

Now create a function library with the following content:

Option Explicit

Public Function MyFunc(Object, MethodName, Arguments, RetVal)
    Print "Welcome."
End Function

Do not associate this library with the test.

Create a recovery scenario with the following properties:

Trigger: Test run error
    Error: Any error
Recovery operation: Function call
    Library: The one you just created
    Function to call: MyFunc
Post-Recovery Test Run Options:
    Process to next action or component iteration

Associate the recovery scenario to the test you created in the beginning. Set "Activate Recovery scenarios:" to "On error".

Run the test. The output is as expected, but the run result looks like this:

Run result with warning

The "Error" node has the following details ("Element nicht gefunden" is german and means "Element not found", I am very surprised to see a localized error message here):

How´s that? It appears that IsEmpty generates such an entry whenever it is called with a test object.

Could it be this is a bug?

My current workaround is to introduce my own IsEmpty function which disables the recovery scenario, calls the original IsEmpty function, and re-enables the recovery scenario. Which is a horror, because the IsEmpty replacement cannot be named IsEmpty. That would result in a recursive call, because I cannot call the original version from the replacement if it has the same name (or can I?). And calling something different when you want to call IsEmpty is easily forgotten.

I cannot live with the warnings generated for every IsEmpty call if a recovery scenario is active.

What´s going on? Can you guys reproduce this? Is there a better workaround?

English (of course) QTP 11.00 build 1018 with .net, ActiveX, Delphi, Java, Oracle, Silverlight, Web, Web Services and WPF add-ins, but none of them active for this demo. Using Hotfixes QTPWEB_00078 and QTPJV_00044. Windows 7.

Update: I just figured I can check for VarType (Obj) = vbEmpty, so I can create an IsEmpty replacement as outlined, but named IsEmpty. I.e. I have a workaround, but still am wondering if this is a QTP bug.

Update 2: The VarType (Obj) reference does not work, it generates the same strange run result warning.

Update 3: It seems IsEmpty cannot be replaced by a function with the same name. It The intrinsic function is always called.

Update 4: The closest one can come to replacing an intrinsic is the method outlined in http://www.knowledgeinbox.com/articles/qtp/advanced-qtp/overriding-default-functions-using-function-pointers/, but it requires a declaration and an assignment in every action script. Sigh.

Was it helpful?

Solution

Aside from the question "How can I override intrinsic functions?" contained in my question, I found a 1:1 replacement for the IsEmpty functionality that does not create this strange log entry with test objects:

Instead of

IsEmpty (P)

use

TypeName (P) = "Empty"

If P is a test object, the IsEmpty call would create the magic log entry, while TypeName doesn't.

And this sure (imho) is a bug in QTP´s recovery scenario functionality.

OTHER TIPS

I wonder if IsEmpty works with not existing QTP objects, or that you are exploring "undefined behaviour" where everything can happen, from inconsistent return values to a format of you hard drive (while the latter is somewhat less probable than the first).

IsEmpty is normally used for uninitialize variables:

Dim a
MsgBox isEmpty(a)  ' --> True
a = ""
MsgBox isEmpty(a)  ' --> False
MsgBox isEmpty(b)  ' --> True or an Error if you use the error resume next statement

Dim obj : set obj = Nothing
MsgBox isEmpty(obj) ' --> False, it contains an object (Nothing is an object)

In QTP, I would recommend to use Browser("index:=0").Exist(0) to see if an object exists and not IsEmpty

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top