Forum Discussion

Sandyapitester's avatar
Sandyapitester
Frequent Contributor
8 years ago

How to pass the whole response value in my POST request - SOAPUI PRO NG

Hi All,

 

I need to pass the whole get response value in my post request, it's possible in soapui pro version 

 

like

 

Get API - will get the response like

 

[

      {

      "NAME": "ABC",

      "Number": "11111",

      "LASTNAME": "TEXT",

      "NAMEINFO":       [

                  {

            "CURRENTDATE": "2016-08-19",

            "SURNAME": "ABC",

            "STATUS": "PASS",

            "CurrentTIME": "04:43:51.52",

            "userINFO": "XY",

            "versionNumber": "11111-111-111-1111-1111111111111"

         },

 

I need to pass whole data in my POST request  like 

 

Post : 

 

[

      {

      "NAME": "ABC",

      "Number": "11111",

      "LASTNAME": "TEXT",

      "NAMEINFO":       [

                  {

            "CURRENTDATE": "2016-08-19",

            "SURNAME": "ABC",

            "STATUS": "PASS",// ( Need to change the status like "STATUS": "FAIL"

            "CurrentTIME": "04:43:51.52",

            "userINFO": "XY",

            "versionNumber": "11111-111-111-1111-1111111111111"

         },

 

 

and before passing the whole data need to change the parameter value too like 

 

 "STATUS": "FAIL" instead of "PASS"

 

It's possible in SOPAUI PRO version 

 

Please guide me am looking for valuable updates

 

1 Reply

  • New2API's avatar
    New2API
    Frequent Contributor

    Hello, you could use JsonSlurper or JsonBuilder to update a Json node.

     

    import net.sf.json.*
    import net.sf.json.groovy.*
    import groovy.json.JsonSlurper
    import groovy.json.JsonBuilder

     

    def RESPONSE = context.expand('${#TestStepName'#Response}').toString()

          RESPONSE = new JsonSlurper().parseText RESPONSE

          RESPONSE .NAMEINFO[0].STATUS = "FAIL"

     

    def NewReq = new JsonBuilder(RESPONSE  //assumusing you have only one item here... for multiple items you have to loop through

     

    testRunner.testCase.testSuite.setPropertyValue("NEWREQ", "${NewReq}") //Update modifield json payload at testcase level property

     

    in the post request's media type section use testCase property expansion method.

    ${#TestSuite#NEWREQ}

     

     

    hope this helps!!!

     

    Regards!