How do I verify the presence of an image?

I have the following line of code in my program to verify that the element is an image:

if (WebUI.verifyImagePresent(findTestObject(‘Co-Sponsor Sign Up/Account Information/SponsorLogo’), FailureHandling.CONTINUE_ON_FAILURE)) {
WebUI.takeScreenshot()
}

When I run it, it returns the following error:

<TestCaseName>FAILED because (of) Unable to verify image present (Root cause: java.lang.IllegalArgumentException: This object don’t have IMAGE_FILE property, please add it)

I have specified the object to be located by the xpath of the image: /html/body/div[2]/div[2]/div/div[2]/div[2]/span/a/img

What I am doing wrong? What do I need to locate the image by?

I am having the same issue, did anyone get back to you on privete mode or did you find any solution for it that you can kindly share?

You have to put your image into ‘Image Settings’ of the test object as a baseline image

Screen Shot 2017-09-08 at 13.49.41.png

Hi Hanh, Can you plz explain a bit more…am facing the same issue, could not find image settings…

Hi there,

verifyImagePresent keyword will scan the current web page to see if there is any image matched with the test object. Therefore, the test object needs to have a source image so that Katalon Studio can use it for comparison. You need to select the image from your local machine in test object’s details.

http://pasteboard.co/ycYpJGe4D.jpg

Katalon Studio has another built-in keyword called “Verify Element Present”. It will NOT compare the image ,but will see whether if that test object is presented on current web page or not using its Xpath.

These keywords have different comparison methods

2 Likes

I think he refers to the following:

image settings.png

Yes, I tried with this…doesn’t work

kindly upload the tutorial for this issue we really need a proper way of using this image keyword.please as soon as possible.

@hadia.aziz@moftak.com:
To use verifyImagePresent, you have to set both Object’s Properties for Object (Id, xpath, class…) and the Image file at the “Image” field to compare . Please view the screenshot.

Then you can use the keyword as normal command:
WebUI.verifyImagePresent(findTestObject(“Page_HTML Images/img_workplace”))

2017-12-27 10_09_41.png

2 Likes

hello, I have set both Object’s Properties and Image file, but this feature this also not working for me. I am running Version: 5.2.0 Build: 1 on Windows.

@ai test said:
hello, I have set both Object’s Properties and Image file, but this feature this also not working for me. I am running Version: 5.2.0 Build: 1 on Windows.

Can you tell me more about ‘not working for me’ issue here? What observations do you see?

Not the original poster but i’m encountering the same issue. Image has been specified in the object (with the path selected for the local .png file). This is the error generated:

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
01-03-2018 04:35:07 PM - [FAILED] - Image: ‘images/boat.png’ is NOT present
01-03-2018 04:35:07 PM - [FAILED] - Unable to verify image present (Root cause: Image: ‘images/boat.png’ is NOT present)
01-03-2018 04:35:07 PM - [END] - End action : verifyImagePresent
01-03-2018 04:35:07 PM - [FAILED] - Test Cases/Automation_TestCases/Automation_Script1 FAILED because (of) Unable to verify image present (Root cause: Image: ‘images/boat.png’ is NOT present)

Hi there,

How can you ‘capture’ the source image used for comparison?

Regards

@Vinh Nguyen said:

@ai test said:
hello, I have set both Object’s Properties and Image file, but this feature this also not working for me. I am running Version: 5.2.0 Build: 1 on Windows.

Can you tell me more about ‘not working for me’ issue here? What observations do you see?

OK, so I have an object, imgObj, in the object repository with Selection Method Basic with an xpath property equals .//img[@ng-src=‘…/images/appimages/logo_116x116.jpg’]
I also saved logo_116x116 jpg into the project root folder.

Then inside testcase, WebUI.verifyImagePresent(findTestObject(‘mypage/imgObj’))

Error I am getting:
Unable to verify image present (Root cause: Image: ‘D:\KatalonStudioProject\myKatalonProj1\logo_116x116.jpg’ is NOT present)

imgObjQuestion.png

OK, I think, I see the reason now: because the image that is saved, logo_116x116.jpg, does not match the image on the web page under test, because on the web page, the image has been scaled down, with width/height attribute.

If I do a screen shot then cut/paste image from web page into new file, test case pass!
Is there a better way to handle image check, when it is scaled down on web page? Any way to specify tolerance for method verifyImagePresent or image that it is verifying?

Just FYI, this is for anyone using dual monitors… I just notice if I moved the browser launched by automated software to the 2nd monitor, then run my 2nd test case, it failed to find the image. If moved browser back to primary window, test case pass.

1 Like

When will SVG images be supported?

1 Like

I’ve found that the verifyImagePresent fails when I try and step over if the browser is not visible on the screen. My guess is that this keyword works by taking a screenshot of browser and searching for the reference image within it.

@Katalon apprentice

Even the keyword WebUI.verifyElementInViewport deprecated from the katalon.

will it work for future.

It seems like there is a lot of confusion about this command and how it really works. Further, the Katalon example is missing some of these details to make it work.

In working with this command it appears there are several points of failure - image resolution on screen vs local copy, the Xpath reference and needing the IMG tag, how it behaves on multiple monitors, whether the browser session is active or in the background, and several other factors.

Is it possible to get some updated examples of how this command should work and what parameters it really needs to be successful?

2 Likes