Forum Discussion

krogold's avatar
krogold
Regular Contributor
6 years ago
Solved

How to get a run test case target's name ?

Hello,

I use a lot of 'run test case' steps in my project and I would like to know if it's possible, in a quite straightforward way, to determine which test case is called by a 'run test case' step ?

I know how to find the type of a test step and if it is a 'calltestcase' step, I may be able to extract the uid of the test case called, but is there a possibility to get the test case's name ?

 

thanks for any idea

 

Alex

  • Place the following Groovy code into a Groovy Test Step within the test case that contains the "Run TestCase" test step, this will demo how to get the target test case name, and how it is different from the test case name.

     

    def runTestCaseStep = testRunner.getTestCase().getTestStepByName('Run TestCase Step Name')
    
    // Log the name of the calling run test case.
    log.info('Run TestCase Step Name = ' + runTestCaseStep.getName())
    
    // Log the name of the target test case being called.
    log.info('Target TestCase Step Name = ' + runTestCaseStep.getTargetTestCase().getName())

    Note: The "Run TestCase" test step is the class WsdlRunTestCaseTestStep.

     

2 Replies

  • Radford's avatar
    Radford
    Super Contributor

    Place the following Groovy code into a Groovy Test Step within the test case that contains the "Run TestCase" test step, this will demo how to get the target test case name, and how it is different from the test case name.

     

    def runTestCaseStep = testRunner.getTestCase().getTestStepByName('Run TestCase Step Name')
    
    // Log the name of the calling run test case.
    log.info('Run TestCase Step Name = ' + runTestCaseStep.getName())
    
    // Log the name of the target test case being called.
    log.info('Target TestCase Step Name = ' + runTestCaseStep.getTargetTestCase().getName())

    Note: The "Run TestCase" test step is the class WsdlRunTestCaseTestStep.

     

  • Hi krogold

     

    Use below code, hope it will help.

     

    ts = testRunner.testCase.getTestStepAt(i)
    def tsRun = ts.run(testRunner, context)
    log.info tsRun.testStep.name

    Click "Accept as Solution" if my answer has helped, and remember to give "kudos" :)

     

    Thanks and Regards,

    Himanshu Tayal