waitForImagePresent always return FALSE

It seems waitForImagePresent has a bug, it always return FALSE even the image is present. Any idea how to workaround it?

it will always print out ‘image not present’ in below code…
if (WebUI.waitForImagePresent(findTestObject(‘Page_Login/smartcard_login_button2’),1,FailureHandling.OPTIONAL))
println ‘image present’
else
println ‘image not present’

Hi Joe,

Try another work around… something like this:

//try getting the image locator, I'm sure there's an attribute representing the image you are trying to automate.

//then instead of using waitForImagePresent, try WebUI.waitForElementPresent or WebUI.waitForElementVisible
if (WebUI.waitForElementPresent(findTestObject("Your_Image_Object"), 30, FailureHandling.OPTIONAL) ||
    WebUI.waitForElementVisible(findTestObject("Your_Image_Object"), 30, FailureHandling.OPTIONAL)
{
    println ‘image present’
}
else
{
    println ‘image not present’
}

Hope that helps. . . :slight_smile:

thanks Arnel for the tips. I just wonder why Katalon didn’t fix this obvious bug of waitForImagePresent.

but what if the image cannot be located in browser, or some dialogs from the OS.
I can use Sikuli to do it.
Another way is to …
try{
(WebUI.waitForImagePresent(findTestObject(‘Page_Login/smartcard_login_button2’),1,FailureHandling. STOP_ON_FAILURE))
println ‘image present’
} catch (Exception e) {
println ‘image not present’
}

Perhaps the definition of your TestObject Page_Login/smartcard_login_button2 has some problem. For example, as https://docs.katalon.com/katalon-studio/docs/webui-wait-for-image-present.html#example sais

The test object needs to define a source image from the local machine for Katalon Studio to use it for verification

Have you defined the source image?


You should be aware that waitForImagePresent() keyword is very strict. It expects the image in the target Web page to be EXACTLY identical to the source image pixel-wise: just the same width, just the same hight, every pixel has same RGB value, no size-scaling should be applied. If a single pixel has different RGB value, then waitForImagePresent() will return FALSE.

What is worse is that waitForImage*() does not give you any diagnostics; instead it just returns FALSE. You would be at a loss what to do next. Due to this single reason, I find waitForImage*() keywords are hard to use. I would rather recommend you not to rely on them. You should find another path.

thanks kazurayam, totally agree!

One good path is Sikuli, which relies on OpenCV. It’s a lot more reliable.
Any better path you recommend for image comparison?

I have ever tried to compare images (screenshots) using aShot.

See the following post of mine:

In this demo project, I calculated the magnitude of difference of 2 given images (source and target) : 0.0%, 0.1%, …, 75.34%, 99.80%, 100.0%. And I put 3rd parameter : criteria-percentage. If I put 1.00% as the criteria, my test regards smaller differences (such as 0.0% and 0.1%) are ignorable; meaning 2 images are similar enough. But greater differences (such as 75.34%, 99.80%, 100.0%) will be regarded significant; meaning 2 images are different.

An now AShot plugin for Katalon Studio is available.