Forum Discussion

Etks's avatar
Etks
Occasional Contributor
8 years ago

Test Step "Run TestCase" How to get test step index of parent test case?

Hi all. I have a REST Project (I'm using SoapUI Pro) where I'm a little stuck.

 

In Test Case A I am using a test step "Run Test Case B". Inside of Test Case B I have a single step: a Groovy script. In this Groovy script I need to extract some information about Test Case A (specifically, test step index). How can I do that?

 

(This is a simplified example. In reality I have several test cases where I have a "Run Test Case B" test step, hence I can't make assumptions about the name of the parent test case etc).

 

Code snippet from the Groovy script in Test Case B:

 

 

...
def currentStepIndex = context.currentStepIndex //Loops back to the previous step x times if(loopCounter < maxLoopCount) { loopCounter++ testRunner.gotoStep(currentStepIndex-1) } ...

 

 

context.currentStepIndex gives me the test step index in Test Case B, but I need to get the test step index in Test Case A.

 

(I've put this loop script into a separate test case for code reuse/maintenance reasons)

 

Thanks for your help. And sorry for posting this in the wrong forum at first, noticed it only now.

  • Etks,

     

    Not sure what your use case is. But that is interesting technically.

     

    And here is how you can get it. By the way, thank your for your search and the link with which I got the clue for the below:

     

    def nContext = context.getProperty("#CallingTestRunContext#")
    log.info nContext.currentStepIndex

     

    • Etks's avatar
      Etks
      Occasional Contributor

      Thanks for your answer, but this doesn't address my problem. The posts in the link you provided explain how to run a test case from a groovy script. But I need to find out the test step number of the parent test case.

       

      To clarify: I have a "helper method" test case (Test Case B in the above example). I insert this test case into other test cases (for example, Test Case A) where needed.

       

      My test cases are built like this:

       

      Test Case A

      --Test Step 1 - SomeRequest

      --Test Step 2 - SomethingElse

      -- ...

      -- Test Step x - Run Test Case B

      -- Test Step x+1 - SomeOtherRequest

       

      Test Case B

      --Test Step 1 - Groovy Script

       

      I need to find out what x is inside the Groovy script in Test Case B.

       

      Since posting this I found out how to reference the parent test case in this link:

      https://community.smartbear.com/t5/SoapUI-Pro/How-to-find-the-parent-Test-Case-of-a-Run-TestCase-step/td-p/18050

      by using the Property #CallingRunTestCaseStep#

       

      But I'm still stuck on how to get the test step.

       

       

      • nmrao's avatar
        nmrao
        Champion Level 3

        Etks,

         

        Not sure what your use case is. But that is interesting technically.

         

        And here is how you can get it. By the way, thank your for your search and the link with which I got the clue for the below:

         

        def nContext = context.getProperty("#CallingTestRunContext#")
        log.info nContext.currentStepIndex