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.