# Custom Keywords take screenshot when failing

**URL:** <https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [October 7, 2019, 10:29pm UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282 "2019-10-07T22:29:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon-Hinds](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon-hinds/32/17892_2.png) [@Brandon-Hinds](https://forum.katalon.com/u/Brandon-Hinds)\
**Post date:** [October 7, 2019, 10:29pm UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/1 "2019-10-07T22:29:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 8, 2019, 12:11am UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/2 "2019-10-08T00:11:03Z")

</div>

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

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

```

See also

> [@Failed test case reusing window when test suite is run?](http://forum.katalon.com/t/failed-test-case-reusing-window-when-test-suite-is-run/30281/10):
>
> I agree. I think we’ll leave this under bug reports for now. I’m not able to set up a reasonable test bed to work this through (time constraints). I’m hoping @devalex88/@ThanhTo can throw some light on it. Meanwhile… try { callTestcase(...) } catch(Exception e) { closeBrowser() // perhaps? // throw e // perhaps? } I’ll also give a shout out to @kazurayam - he’s done some work in this area, I believe (but he’s likely not around for a good few hours)

---

<div class="post-metadata">

**Author:** ![Brandon-Hinds](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon-hinds/32/17892_2.png) [@Brandon-Hinds](https://forum.katalon.com/u/Brandon-Hinds)\
**Post date:** [October 8, 2019, 1:04am UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/3 "2019-10-08T01:04:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 8, 2019, 1:08am UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/4 "2019-10-08T01:08:40Z")

</div>

> [@Brandon-Hinds](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 8, 2019, 1:15am UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/5 "2019-10-08T01:15:43Z")

</div>

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.

> [@Create Allure Report extention Plugin](http://forum.katalon.com/t/create-allure-report-extention-plugin/33279):
>
> I am willing to contribute Katalon Community to create a Plugin for Allure reports. Please can some one let me know if there is any way we can use Allure Plugins API to generate Allure reports.

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

---

<div class="post-metadata">

**Author:** ![Brandon-Hinds](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon-hinds/32/17892_2.png) [@Brandon-Hinds](https://forum.katalon.com/u/Brandon-Hinds)\
**Post date:** [October 8, 2019, 2:14am UTC](https://forum.katalon.com/t/custom-keywords-take-screenshot-when-failing/34282/6 "2019-10-08T02:14:23Z")

</div>

> 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
