Forum Discussion

aaronpliu's avatar
aaronpliu
Frequent Contributor
5 years ago
Solved

Call test step of another test case through Groovy

Hi friends,

 

A common test scenario to call test step of another test case in SoapUI. My question is that how does called test step (REST GET request) retrieve property value? (i.e. one parameter is ${#TestCase#userID}). when I call this step using below Groovy code:

(Example)

Case 1
    REST Step 1
    REST Step 2
Case 2

    Groovy Step 1

// call "REST Step 1" of Case 1 in Case 2
def targetTestStep = testRunner.testCase.testSuite.testCases["Case 1"].testSteps["REST Step 1"]
targetTestStep.run(testRunner, context)

"REST Step 1" has a parameter with "${#TestCase#userID}", if run above code, the "REST Step 1" cannot get property value from "Custom Properties" of test case. It seems retrieve property value from caller's properties rather than called one. is it about "testRunner"? 

If I want called test step to get property value from its own test case. How can I proceed it?

 

Thanks 

 

Regards,

/Aaron

 

 

  • While I have not actually tried this, the documentation...

     

    https://support.smartbear.com/readyapi/docs/testing/properties/expansion.html#scopes

     

    ...states "To refer to properties in other test suites or test cases, use the full "path" to specify the desired scope.
    The "path" part is enclosed in square brackets.", with the example:

     

    ${#[Suite name#Case name#Step name]#Property name} 

     

    Take a read of the docs for a more complete explanation.

     

5 Replies

  • Radford's avatar
    Radford
    Super Contributor

    While I have not actually tried this, the documentation...

     

    https://support.smartbear.com/readyapi/docs/testing/properties/expansion.html#scopes

     

    ...states "To refer to properties in other test suites or test cases, use the full "path" to specify the desired scope.
    The "path" part is enclosed in square brackets.", with the example:

     

    ${#[Suite name#Case name#Step name]#Property name} 

     

    Take a read of the docs for a more complete explanation.

     

    • aaronpliu's avatar
      aaronpliu
      Frequent Contributor

      yes, Radford understand what I raised question. replaced parameter from ${#TestCase#UserID} to ${#[testSuite Name#testCase Name]#UserID}, then called test step can retrieve its own properties from test case level.

       

      However, it's not a perfect approach for it. assumed that you have a shared test case, and someday the test suite name / test case name changed, you have to update shared test case / test steps since you reference testSuite / testCase name in parameterized value.

       

      What's difference for above 2 parameters?

       

      Regards,

      /Aaron

  • Hi aaronpliu ,

     

    I would suggest you to set the property value dynamically, by using following set of code,

    def valueToSet = "value to set"
    testRunner.testCase.testSuite.testCases["Case 1"].setPropertyValue("property name", valueToSet);
    
    • Olga_T's avatar
      Olga_T
      SmartBear Alumni (Retired)

      Thanks guys!

       

      aaronpliu, have you had a chance to try the suggestions above?

      • royki's avatar
        royki
        Occasional Contributor

        It seems that you set the custom property as testCase label not testStep label.
        And are you sure custom property is called properly when you run the testStep. Did you check to run manually step by steps ? 

        testStep should have the reference of that custom property.

        You can follow this in your groovy scipt - 

        def project = context.testCase.testSuite.project
        def TestSuite = project.getTestSuiteByName("TestSuite_Name")
        def testCase1 = TestSuite.getTestCaseByName("Case 1")
        def testStep1 = testCase1.getTestStepByName("REST Step 1")
        def testStep2 = testCase1.getTestStepByName("REST Step 2")
        def testCase2 = TestSuite.getTestCaseByName("Case 2")
        def groovyStep = testCase2.getTestStepByName("Groovy Step 1")

        // To retrive the property - from testStep => In your case you don't need this.
        def customProperty = testStep1.getPropertyValue("UserID")

        // To retrive the property - from testCase; if you already have the custom property set and value is defined
        def customProperty = testCase1.getPropertyValue("UserID")

        // You have to set custome property to your testStep (I guess the problem appears here)
        // I don't know the testStep property name where the `userID` value will be set. so just change the name of this property
        testStep1.setPropertyValue("testStepProperty", customProperty)

        Execute
        groovyStep.run(testRunner, context)

         

        Hope this would work.