1
votes

We are testing an GUI with UFT 14.52. For each Popup, Schema, View we have an single Component. I would like to add validations points for each component, so i can validate that the application is in the right state.

For Example: I do have this Popup and an Component which handles the Popup (selecting street, and clicking buttons).

Popup

When the Component starts, i want to verify that the Popup is up. With UFT Checkpoints this works flawless by using enabled as identification.

enabled as identification

But if i want an verification point at the end (Check if the Popup is closed via enabled) i do get an "object not found exception from uft" as expected, because the given popup is closed. Validing the object is not existing by JavaObject.Exist(5) is not feasible because it will actually wait the timeout and then return the state.

Is there any workaround for this? Is there something similar as javaObject.NonExists(5)? Is this state validation at the end even useful?

1
If Not javaObject.Exist(5) Then should work for your requirement - Dave
@Dave a negation of javaObject.Exist(5) wont work because the script will actually wait 5 seconds and after this returns false (and then get negated by not). So the explicit wait will get converted to an implizit wait... - Jonas
Yep - that's right. Exist is boolean and tests for both conditions (true = it's there and false = it's not) so there's no such thing as a Nonexist - it is essentially the same thing as Exist with a different name. If all you want is to speed things up, maybe reduce the wait to half a second if you're not expecting the object to be present - Dave
Exist will return either once the object is found or after the timeout elapses (whichever comes first) if you want to check if the object exists without waiting just pass 0 as the timeout. As @Dave said, there's no logical need for NotExist. Perhaps we've misunderstood the question, if so please try to clarify. - Motti
I just finished writing an answer assuming your question is more complex :( Well I'll add the Exist(0) and leave it in case it helps someone in the future. - Motti

1 Answers

2
votes

One thing to note is that the timeout parameter to Exist doesn't default to zero, so if you want it to return right away if the object doesn't exist you should use obj.Exist(0).

If my understanding is correct, you want to mimic the behaviour of Exist so that if the condition fails (the object does exist in this case) then the function doesn't return False immediately but waits the timeout for it to become True (for the object not to exist).

If so you can try this:

Public Function NotExist(ByRef test_object, ByVal timeout)
       Deadline = DateAdd("s", timeout, Now)
       While test_object.Exist(0)
            If DateDiff("s", Now, Deadline) < 0 Then
                NotExist = False
                Exit Function
            End If  
            test_object.RefreshObject ' not sure if this is needed
       Wend

       NotExist = True
End Function
RegisterUserFunc "JavaObject", "NotExist", "NotExist"

The only subtle part here is the RefreshObject which I thought was needed but it worked without it when I tried it with Web addin (I don't use Java).

I think it should be needed since UFT caches the object if it's found but perhaps Exist clears this cache (further reading on this caching mechanism).