Forum Discussion

rohgoyal's avatar
10 years ago

Pass JSON Content to Next Test Step using Properties Tranfer

I am creating a 3 step testcase.

1st step is Groovy Script which read a file that has JSON content. I am able to read it successfully. Say this is the JSON content read from file.
{"name":"John Sid"}


3rd step is a "HTTP Call" to a endpoint with JSON messages. Currently I have mentioned this in request body.
{"body":"<ReplaceThisString>"}


2nd step, I have used Properties Transfer step to pass read JSON content from 1st step to 3rd step "HTTP Call". Problem is I need to replace <ReplaceThisString> with the JSON content read from first step. So this is what I want after execution of the Properties Transfer step.
{"body":"{\"name\":\"John Sid\"}"}


Can any one help, how can I do that?

- Rohit

1 Reply

  • jigarpatel's avatar
    jigarpatel
    New Contributor

    //From first TestStep read JSON string in a variable and then set it as property in the third test step
    //Here I assume you already have a way to read JSON file
    def jsonString = '{"name":"John Sid"}'
    def targetTestStepIndex = context.currentStepIndex + 2
    context.testCase.getTestStepAt(targetTestStepIndex).setPropertyValue("propertySetFromFirstStep", jsonString)


    In 3rd Step request, you probably don't want quotes around json object.


    {
    "body": ${propertySetFromFirstStep}
    }