shyne
2 years agoOccasional Contributor
Groovy - Get the name of the test case that called the "Run Test Case" for this test case
Get the name of the test case that called the "Run Test Case" for this test case in Groovy:
- Test Suite: "ABC" has Test case "ABC123",
- which has a "Run Test Case" step,
- that runs "CommonTest1" test case (in Test Suite "Common").
I want the Groovy script in CommonTest1 to log/use the name of the Test case that called it. That is: "ABC123". Ideally without passing in "context.currentStep.name" as a parameter.
Help much appreciated.
Yes, got it.
Here is the script needed:
def showCallTrace = { def step = context.'#CallingRunTestCaseStep#' def myname = { it.name } log.info "I am called by ${myname(step)} step of ${myname(step.parent)} test case of ${myname(step.parent.parent)} suite" } showCallTrace()