Environment variable for TestCase Name?

Hi. Is there a built-in variable for the current test case name? I’m doing a testcase teardown in a testsuite and need the current test case name.

Best way I’ve found is to use Test Listeners: https://docs.katalon.com/pages/viewpage.action?pageId=5126383

You can copy the testCaseId to a global variable and use it throughout your test(s).

  def beforeTestCase(TestCaseContext testCaseContext) {
    GlobalVariable.TCID = testCaseContext.testCaseId

You will need to create the global variable before hand and set it to “” (empty).

Note: I haven’t proved these are available in the setup/teardown methods – hopefully, it will work.


Thank you Russ! I’ll give it a try.

This is exactly what I needed…thanks!

Glad it worked. B)

Robert, because I wasn’t certain about using that code at or within your suite code, could you paste in the relevant code so that others may find it later?


Actually directly using the AfterTestCase listener did the trick. I set tcName to testCaseContext.getTestCaseId(). I ended up not using the Global variable. I was not previously aware of testCaseContext… it really helped.

class EndTest {
* Executes after every test case ends.
* @param testCaseContext related information of the executed test case.
def AfterTestCase1(TestCaseContext testCaseContext) {
String tcName = testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseId()
String tcStatus = testCaseContext.getTestCaseStatus()
println testCaseContext.getTestCaseStatus()
println testCaseContext.getTestCaseVariables()