Customize exception to console

I have a try catch for an exception but it still shows in the console, is there any way to prevent or minimize the exception thrown from a caught exception?

This causes a lot of unneeded information for my particular case and clutters the console for debugging

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!

Hi @eric.fabiszewski,

It is great to hear from you. Can you please help share your code and the result to let us help you?

Let me explain by example.

I have a Test Case which intentionally fails:

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.model.FailureHandling as FailureHandling


TestObject makeTestObject(String id, String xpath) {
	TestObject tObj = new TestObject(id)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj	
}

WebUI.openBrowser('')
WebUI.navigateToUrl("http://demoaut.katalon.com")
WebUI.verifyElementPresent(makeTestObject("foo","//div[@id='bar']"), 3, FailureHandling.OPTIONAL)
WebUI.delay(1)
WebUI.closeBrowser()

When I ran this, I saw the following output in the console:

2024-08-03 20:29:08.252 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-08-03 20:29:08.256 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/SuppressedError
2024-08-03 20:29:08.893 DEBUG testcase.SuppressedError                 - 1: openBrowser("")
2024-08-03 20:29:09.346 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Chrome' driver
8月 03, 2024 8:29:09 午後 org.openqa.selenium.remote.DesiredCapabilities chrome
情報: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
2024-08-03 20:29:09.416 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 milliseconds
Starting ChromeDriver 126.0.6478.126 (d36ace6122e0a59570e258d82441395206d60e1c-refs/branch-heads/6478@{#1591}) on port 4620
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1722684553.192][WARNING]: This version of ChromeDriver has not been tested with Chrome version 127.
8月 03, 2024 8:29:13 午後 org.openqa.selenium.remote.ProtocolHandshake createSession
情報: Detected dialect: W3C
2024-08-03 20:29:13.666 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId = 67e90102633d1ea4bfa5d02a4f619d4a
2024-08-03 20:29:13.696 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 127.0.0.0
2024-08-03 20:29:13.711 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Mac OS X
2024-08-03 20:29:13.731 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 3.141.59
2024-08-03 20:29:13.752 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = ProxyInformation { proxyOption=NO_PROXY, proxyServerType=HTTP, username=, password=********, proxyServerAddress=, proxyServerPort=0, executionList="", isApplyToDesiredCapabilities=true }
2024-08-03 20:29:13.820 DEBUG testcase.SuppressedError                 - 2: navigateToUrl("http://demoaut.katalon.com")
2024-08-03 20:29:19.873 DEBUG testcase.SuppressedError                 - 3: verifyElementPresent(makeTestObject("foo", "//div[@id='bar']"), 3, OPTIONAL)
2024-08-03 20:29:19.917 DEBUG testcase.SuppressedError                 - 1: tObj = new com.kms.katalon.core.testobject.TestObject(id)
2024-08-03 20:29:19.960 DEBUG testcase.SuppressedError                 - 2: tObj.addProperty("xpath", EQUALS, xpath)
2024-08-03 20:29:19.989 DEBUG testcase.SuppressedError                 - 3: return tObj
2024-08-03 20:29:24.193 INFO  c.k.k.c.webui.common.WebUiCommonHelper   - Unable to find the element located by 'By.xpath: //div[@id='bar']'. Please recheck the objects properties to make sure the desired element is located. 
2024-08-03 20:29:25.808 WARN  c.k.k.core.keyword.internal.KeywordMain  - com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='bar']' not found (Root cause: com.kms.katalon.core.exception.StepFailedException: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='bar']' not found
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:85)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1448)
	at SuppressedError.run(SuppressedError:15)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at TempTestCase1722684541599.run(TempTestCase1722684541599.groovy:25)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
)
2024-08-03 20:29:25.822 DEBUG testcase.SuppressedError                 - 4: delay(1)
2024-08-03 20:29:26.932 DEBUG testcase.SuppressedError                 - 5: closeBrowser()
2024-08-03 20:29:27.301 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/SuppressedError

Now I would assume that @eric.fabiszewski want to suppress the 25 lines of stack trace, that is

2024-08-03 20:29:25.808 WARN  c.k.k.core.keyword.internal.KeywordMain  - com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='bar']' not found (Root cause: com.kms.katalon.core.exception.StepFailedException: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'foo' located by '//div[@id='bar']' not found
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.doCall(VerifyElementPresentKeyword.groovy:85)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword$_verifyElementPresent_closure1.call(VerifyElementPresentKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.verifyElementPresent(VerifyElementPresentKeyword.groovy:92)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementPresentKeyword.execute(VerifyElementPresentKeyword.groovy:68)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent(WebUiBuiltInKeywords.groovy:1448)
	at SuppressedError.run(SuppressedError:15)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:448)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:439)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:418)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:410)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:285)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:144)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:135)
	at TempTestCase1722684541599.run(TempTestCase1722684541599.groovy:25)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
)

Yes, it is possible to suppress this stack trace message. But how to?

ANSWER

In all Katalon project, you have a file Include/config/log.properties. In this file, you want to insert a line:

logging.level.com.kms.katalon.core.keyword.internal.KeywordMain=ERROR

This line specifies that the messages from com.kms.katalon.core.keyword.internal.KeywordMain of level lower than ERROR should be filtered out; won’ be printed to the console.

Accepted log level includes ERROR , WARN , INFO , DEBUG and TRACE .

With the log.properties file edited, you want to try the same Test Case. You would find that the verbose stack trace is not emmited any longer.

2024-08-03 20:34:29.401 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-08-03 20:34:29.409 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/SuppressedError
2024-08-03 20:34:30.118 DEBUG testcase.SuppressedError                 - 1: openBrowser("")
2024-08-03 20:34:30.534 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Chrome' driver
8月 03, 2024 8:34:30 午後 org.openqa.selenium.remote.DesiredCapabilities chrome
情報: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
2024-08-03 20:34:30.619 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 milliseconds
Starting ChromeDriver 126.0.6478.126 (d36ace6122e0a59570e258d82441395206d60e1c-refs/branch-heads/6478@{#1591}) on port 4144
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1722684874.588][WARNING]: This version of ChromeDriver has not been tested with Chrome version 127.
8月 03, 2024 8:34:34 午後 org.openqa.selenium.remote.ProtocolHandshake createSession
情報: Detected dialect: W3C
2024-08-03 20:34:35.021 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId = 9d0e62df38d9e435df0217ba0a6e335a
2024-08-03 20:34:35.130 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 127.0.0.0
2024-08-03 20:34:35.153 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Mac OS X
2024-08-03 20:34:35.180 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 3.141.59
2024-08-03 20:34:35.195 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = ProxyInformation { proxyOption=NO_PROXY, proxyServerType=HTTP, username=, password=********, proxyServerAddress=, proxyServerPort=0, executionList="", isApplyToDesiredCapabilities=true }
2024-08-03 20:34:35.248 DEBUG testcase.SuppressedError                 - 2: navigateToUrl("http://demoaut.katalon.com")
2024-08-03 20:34:41.239 DEBUG testcase.SuppressedError                 - 3: verifyElementPresent(makeTestObject("foo", "//div[@id='bar']"), 3, OPTIONAL)
2024-08-03 20:34:41.266 DEBUG testcase.SuppressedError                 - 1: tObj = new com.kms.katalon.core.testobject.TestObject(id)
2024-08-03 20:34:41.315 DEBUG testcase.SuppressedError                 - 2: tObj.addProperty("xpath", EQUALS, xpath)
2024-08-03 20:34:41.337 DEBUG testcase.SuppressedError                 - 3: return tObj
2024-08-03 20:34:45.602 INFO  c.k.k.c.webui.common.WebUiCommonHelper   - Unable to find the element located by 'By.xpath: //div[@id='bar']'. Please recheck the objects properties to make sure the desired element is located. 
2024-08-03 20:34:47.317 DEBUG testcase.SuppressedError                 - 4: delay(1)
2024-08-03 20:34:48.380 DEBUG testcase.SuppressedError                 - 5: closeBrowser()
2024-08-03 20:34:48.766 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/SuppressedError

See the katalon documentation on log configuration

This explains how you can use Include/confing/log.properties.

I am afraid that this document is not informative. It tells you no idea how to utilize the feature effectively.

I think that this case (suppressing the stack trace of keyword failure) is a useful case.

I would propose another usefull case:

logging.level.testcase=INFO

This will make the output into the console much less verbose, easier to read.

Have a look at the following post of mine.

This explains a situation where try {} catch {} in your Test Case script fails to catch exceptions.

Hi @kazurayam, I tried adding these lines into my Include/config/log.properties

logging.level.com.kms.katalon.core.keyword.internal.KeywordMain=ERROR
logging.level.com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain=ERROR
logging.level.com.kms=ERROR

yet, in console I can see detailed stack trace that ‘supposed’ to be caught in try/catch statement, do you have any idea if I am doing something wrong?

No, I have no idea.

Customizing Exception handling is a sort of dirty hack. It requires a lot of hands-on experiments. It heavily depends on the runtime environment. I would need your project entirely disclosed to public so that I can run it on my machine in my hand to hack into it. I would need the URL of the Application Under Test to be public so that I can freely access to it via the Internet. Otherwise I can not do any further investigation.