Custom Keywords take screenshot when failing

The out-of-the-box WebUI keywords always take a screenshot of the application when they throw an error, which is very useful when reading over the execution reports. Unfortunately, my custom keywords (which I use often) do not take the same screenshot, and it is much harder to determine the actual error.

I have looked over these forums, and even read some of the WebUI keyword source code, but have not had any luck determining how to take the screenshot. I also doubt I am the first person to have this problem, so I’m wondering if anyone has had this problem before and, if so, how did you fix it.

Thanks in advance.

All you need to do is to catch Exceptions and take screenshots in the catch clause:

try {
  WebUI.callTestcase(...)  
} catch(Exception e) {
  WebUI.takeScreenshot(file)
  // throw e // perhaps?
}

See also

Hi @kazurayam, thanks for the quick response. Does taking a screenshot this way have the same functionality as the out-of-the-box keywords, in that the screenshot is embedded in the reports?

in the KS-built-in Basic Report? Unfortunately not.

The KS-built-in Baseic Report is not customizable at all.
Therefore you can not change it to include images you took.

Some bright guys are working on developing plugins which introduce Reporting frameworks (Allure, Extent, …) into Katalon Studio. I am not familiar with it at all, though.

Their work may enable us to create reports which include the images you took.

2 Likes

in the KS-built-in Basic Report? Unfortunately not.

That’s a shame. I will reassess how we use our current custom keywords to try to increase their usability in the event of errors. Your suggestion about calling the normal keyword may need to be the way this is done.

Their work may enable us to create reports which include the images you took.

Fingers crossed! I will follow the plugins forums more closely to see how they progress.

Thanks for your help @kazurayam