Screenshot not being taken

We are using latest version of Katalon Studio 9.6.0

screenshots are not being taken when test case is failed, no matter what we try.

  • you can see that we have that option enabled (see number 1 in the screenshot)
  • you can see that test case has been marked as failed (see number 2 in the screenshot)
  • it was failed due to sample assertion (see number 3) in the screenshot

but if I go to the ‘Image’ tab, no screenshot is present.

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

The option “Take Screenshot when execution failed” works as a side-effect of a failure of Katalon built-in keywords (e.g, WebUI.verifyElementPresent, etc).

@mateusz.mysliwiec

You wrote

assert 1== 2

The assert is a Groovy’s built-in statement. It is not a call to a Katalon built-in keyword.

Therefore no screenshot will be taken when assert threw an exception.


Not all of built-in keywords result screenshots taken when failed. Some keywords do, others don’t.

Do you want to know which keywords do, which kewyords don’t? — I think there is no document that answers to the question. All you can do is to read the Groovy source codes of each keywords.

I would show you an example.

How to get the souce

On my mac, I have the /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/source folder which contains jar files of com.kms.katalon.core source codes. You, a Windows user, would be able to find the same in the folder where you installed Katalon Studio.

I unzipped the 2 jar files

  • /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/source/com.kms.katalon.core/com.kms.katalon.core-sources.jar
  • /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/source/com.kms.katalon.core.webui/com.kms.katalon.core.webui-sources.jar

Read the source of WebUI.verifyElementPresent keyword

I found the source code of that class in Groovy
VerifyElementPresentKeyword.groovy (4.2 KB)

I read the code and found that the following portion is concerned about screenshot. See Line#84-85

            } catch (WebElementNotFoundException ex) {
                WebUIKeywordMain.stepFailed(
                        ExceptionsUtil.getMessageForThrowable(ex), 
                        flowControl,
                        null,
                        true   // to take screenshot or not?
                        )

Please find that, when the WebUI.verifyElementPresent keyword raised a WebElemewntNotFoundException, WebUIKeywordMain.stepFailed method is called.

The stepFailed method performs the process of taking screenshots.

You should check the 4th parameter to the stepFailed method, The 4th parameter is a boolean type, which expresses if the caller requires taking screenshot, or not.

The WebUI.verifyElementPresent keywords specifies true to the 4th argument to the WebUIKeywordMain.stepFailed methods. Therefore, a screenshot will be taken if verifyElementPresent keyword failed.

Some other keywords specify false to WebUIKeywordMain.stepFailed invokation. For example, WebUI.click keywords.

And some other keywords does NOT invoke WebUIKeywordMain.stepFailed at all. For example, WebUI.UploadFile keyword.

Each keyword has its own behavior. They behave differently on failure.

WebUIKeywordMain.stepFailed method takes a screenshot on a failure of built-in keyword. It is a magic spell. Do you want to learn it?

To demonstrate how the spell works, I have made an example Test Case that calls the stepFailed of WebUIKeywordMain directly.

Test Cases/TakingFakeScreenshotOnFailure

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.util.internal.ExceptionsUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain

def doSomethingFunny(a, b) {
	if (a != b) {
		throw new IllegalArgumentException("${a} is not equal to ${b}")
	}
}

WebUI.openBrowser("http://demoaut.katalon.com");

def value = 1
try {
	doSomethingFunny(value, 2);
} catch (Throwable ex) {
	WebUIKeywordMain.stepFailed(
		ExceptionsUtil.getMessageForThrowable(ex),
		FailureHandling.CONTINUE_ON_FAILURE,
		null,
		true); // I want to take a screenshot on this event, though the screen has nothing to do with the doSomethingFunny function
}

WebUI.closeBrowser()

I made a Test Suites/TS1 which includes the above Test Case.

I ran the TS1. The Test Case failed as expected.

I got the following report which includes a screenshot PNG.

20240810_094113.pdf (5.3 MB)

With this dirty hack, your test case can take screenshots whenever you want, and let the PNGs attached into the Basic report.

As you see, the doSomethingFunny function has nothing to do with web browser. The screnshot was taken successfully because the Test Case directly called the stepFailed method and, just accidentally, the Test Case had an active connection to a browser. If the Test Case has no active connection to a browser by chance, then it will log a message “Cannot take screeshot” and that’s all.

2 Likes

Thank you for detailed response, that makes sense and steered me into right direction, marked your response as Solution.

1 Like