I have made a demo project on Github:
Solution
Manually editting logback.xml file is not a good idea. I should modify logback LoggerFactory object runtime. I should be able to do it using Groovy’s metaprogramming feature.
Description
I made a custom keyword com.kazurayam.ksbackyard.CustomLoggerFactory
. I would not explain this code much. It performs a surgery for LogBack LoggerFactory object using Groovy’s ExpandoMetaClass.
I made a test case CustomizeLogger4CommentKeywordDemo
, that is:
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// make a patch to the Logback LoggerFactory object runtime
CustomKeywords.'com.kazurayam.ksbackyard.CustomLoggerFactory.customizeLogger4CommentKeyword'()
def arg0 = 2
def arg1 = 3
def result = arg0 + arg1
WebUI.comment("arg0 + arg1 = ${result}")
When I ran the test case, in the Console I see the following messages:
2019-01-11 14:31:12.826 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-01-11 14:31:12.826 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/CustomizeLogger4CommentKeywordDemo
2019-01-11 14:31:13.579 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ksbackyard.CustomLoggerFactory.customizeLogger4CommentKeyword is PASSED
arg0 + arg1 = 5
2019-01-11 14:31:13.774 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/CustomizeLogger4CommentKeywordDemo
I like this plain output:
arg0 + arg1 = 5
I have got a success.
How to reuse it for you
You can copy the keyword com.kazurayam.ksbackyard.CustomLoggerFactory
and paste it into your Katalon Studio project.
And in your test case, call CustomKeywords.'com.kazurayam.ksbackyard.CustomLoggerFactory.customizeLogger4CommentKeyword'()
.
Then WebUI.comment()
will become brief to the point.