I need to get testcase name and pass it to keywordutils, is it possible ?
In the Test Listener, in the method annotated with @BeforeTestCase, you can retrieve the id of current test case. If you want to refer to the current TestCaseId in your test case scripts, you want to add a GlobalVariable which carries the current Test Case ID.
class NewTestListener {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println "testCaseContext.getTextCaseId()=${testCaseContext.getTestCaseId()}"
GlobalVariable.currentTestCaseId = testCaseContext.getTestCaseId()
}
And in a Test case you can refer to the GlobalVariable:
WebUI.comment(">>> currentTestCaseId=${GlobalVariable.currentTestCaseId}")
thank you @4280-kazurayam
Sorry to hi jack this thread @kazurayam and @Didit_Setiawan
From my understanding above, it seems you need to need to hardcode the test case name from the “profile” so this may not work for multiple test cases you want to run under the profile.
How about getting the current test case id/name from the same test case script (I am integrating and passing the test case name ID from Katalon to JIRA)?
No. Your understanding is wrong.
Please read the following code again more carefully; please find how the value of GlobalVariable.currentTestCaseId
is resolved; it is found dynamically by calling testCaseContext.getTestCaseId()
.
class NewTestListener {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println "testCaseContext.getTextCaseId()=${testCaseContext.getTestCaseId()}"
GlobalVariable.currentTestCaseId = testCaseContext.getTestCaseId()
}
Hi @kazurayam yes I was able to resolve it with dynamic use of test case. I used your code as baseline. Thanks again