Get name of Test Case in my code

Hi Katalon Community,

I would like to get the name of my TestCase in my TestCase.

I don’t know how do to this.

Does anyone know how to do please ?

Thank you

You need the TestCaseContext object passed to a test case listener. The name of the Test Case is stored in the testCaseId property…

  @BeforeTestCase
  def beforeTestCase(TestCaseContext testCaseContext) {
    WebUI.comment("beforeTestCase: " + testCaseContext.testCaseId)
  }

You could set up a GlobalVariable.tcid = "unknown" and set it to the correct name in the listener:

  @BeforeTestCase
  def beforeTestCase(TestCaseContext testCaseContext) {
    GlobalVariable.tcid = testCaseContext.testCaseId
    WebUI.comment("beforeTestCase: " + GlobalVariable.tcid)
  }
2 Likes