Forum Discussion

BouncyBall's avatar
New Contributor
6 years ago

Passing a value in a Groovy request and catching the response



I am really having trouble with this simple groovy script. I have a SOAP service that takes a single parameter and I just want to pass the parameter as a variable and catch the response. The request outputs the correct structure with the value I passed but the response is always empty.


I passed the parameter in the SOAP request as ${x} and wrote some code like this :


def durp = context.x = "000000000009006087"

def request = context.expand( '${RetrieveEquipmentModelDetail#Request}') request.toString()
// context.toString()
def response = context.expand( '${$request#Response}')
// context.toString() response.toString()

5 Replies

  • If you are needing to get your response use this instead


    def response = context.expand( '${RetrieveEquipmentModelDetail#Response}')

  • BouncyBall's avatar
    New Contributor

    Didn't work yet. I turned the groovy code into this:

    context.x = "000000000009006087"
    def request = context.expand( '${RetrieveEquipmentModelDetail#Request}') request.toString()
    def response = context.expand( '${RetrieveEquipmentModelDetail#Response}') responseSAPxml.toString()

    The request shows that the context.x value is indeed inserted in the request. Also, I tried actually entering the value manually and running the request and then it returns the correct response but it does not happen when I do it in my code. I think the request is being sentbut in the catching of the response something goes wrong. It's always a blank reponse as if the value in the request was blank. It doesn't feel like I am catching the response from the request.

  • Lucian's avatar
    Community Hero

    Hi, let's start from the beginning.


    When you send a SOAP request the response is automatically saved in a custom propertySketch.png


    This can simply be referenced later from a groovy script as:

    context.expand( '${TestStepName#Response}')

     Be aware that the test step name is case sensitive.


    Anyways.. if it happens for you to receive only some headers with no body then the response will appear empty. You can still get the raw response though you will need to use:


    new String(testRunner.testCase.testSteps["TestStepName"].testRequest.response.rawResponseData)
  • BouncyBall's avatar
    New Contributor



    Thanks for the response.

    I checked in the custom properties what the request value is and it is ${x}. So it seems that when my script runs, he does not use the values I provide.

    Also my script fails if I don't run the SOAP request manually first. But if I then run the script, it will always take the result of the manual SOAP request execution. It's like the script doesn't trigger a new request but just keeps working on the manually run request.


    My SOAP request looks like this (left the SOAP header out for privacy reasons):

                <!--Zero or more repetitions:-->

    My script is this:

    context.x = "000000000099007809"
    def response = context.expand( '${RetrieveEquipmentModelDetail#Response}') response

    There is not other step involved. It's just the SOAP request and a Groovy script.

  • nmrao's avatar
    Champion Level 3

    What is your use case?
    Can you not use custom property and use it with the help of property expansion.