Verify Element In Viewport problem

So, api-docs.katalon.com for verifyElementInViewport says:

Returns:

true if element is present and visible in viewport; otherwise, false

My script says:

if (WebUI.verifyElementInViewport(target, 5, FailureHandling.CONTINUE_ON_FAILURE)){
KeywordUtil.markFailedAndStop('!!!!!')
}

The goal is to check if the form is closed, before continuing to the next step. When I observe the execution of this test, I can see the form getting closed and the test continuing. However, when it reaches the end, test fails and I get the following message:

Test Cases/TC-0034 FAILED because (of) Object 'Object Repository/DUMMY' is present but is not visible in viewport

Why this happens? Shouldn’t the test be passed? The element is NOT visible so the if loop should just skip and continue the test. Am I doing something wrong?

Hi Mate

I’m not sure I’m understanding what you are trying to achieve (relax - that’s probably my fault, not yours ;))

So, assuming I understand correctly, your form should at some point be closed and if that is NOT the case, the AUT is at fault. Correct?

Then… why not do this:

WebUI.verifyElementNotInViewport(target, 20)

Note here a couple of things:

1 - this API is essentially a “wait” interface. It “waits” up to the specified number of seconds.

2 - It’s stating the required state and will fail (since we didn’t add FailureHandling) if it can’t be reached in the allotted twenty seconds.

3 - No need for an IF. The API implies a “loop” that will repeatedly check the state for the 20-second wait period.

Let me know if I misunderstood…

Russ

Hi Russ

You understood correctly what I wanted. However, I added the IF part because I would like to print a message in case of failure.
I tried also with WebUI.verifyElementNotInViewport(target, 20): my form is closed, I can see that (visually), but now I get the following message:
Unable to verify if object ‘Object Repository/DUMMY’ is not visible in viewport (Root cause: Object ‘Object Repository/DUMMY’ is present but is visible in viewport).
I’m starting to doubt if the command is functioning as intended. Can anyone confirm it is working correctly?

Hi Mate,

You need to use FailureHandling.OPTIONAL instead of FailureHandling.CONTINUE_ON_FAILURE!

Let me know if it works for you!