json - SoapUI: Extract Response Value from an Array and Pass Along to Next Request -


i'm hoping can me once again!

i figured out how extract value rest response in simple scenario , pass value along preceding test step, however, i'm stumped on how extract value array within rest response (shown below) use in preceding test step.

more specifically, i'm attempting extract 1 of "id" values within answerchoices.

response payload:

(get) localhost/ws/portal/survey/question/${create ux survey question#responseasxml#//*:id}     {        "id": 589,        "isenabled": true,        "type": "radio",        "wording": "soapui test ux survey question",        "answerchoices":    [                 {              "id": 1546,              "order": 4,              "text": "choice4"           },                 {              "id": 1543,              "order": 2,              "text": "choice2"           },                 {              "id": 1544,              "order": 3,              "text": "choice3"           },                 {              "id": 1545,              "order": 1,              "text": "choice1"           }        ]     } 

i'm trying pass along 1 of answerchoices:id questionchoiceid value in next request (shown below).

(post) localhost/ws/portal/survey/alert  {   "questionchoiceid" : ${},   "restaurantid" : ${create new restaurant#responseasxml#//*:id},   "alertprofileid" : ${#project#emailalertprofileid} } 

i cannot figure out, i've tried declaring namespace in property transfer , thing confuses me. direction point me in appreciated!

i figured out! so, wanted make sure posted answer in case else ran same problem!

i wrote groovy script , did following:

  1. i created 2 project custom properties (negativesurveyanswer , positivesurveyanswer)
  2. add groovy test step , added following code:

    def groovyutils = new com.eviware.soapui.support.groovyutils(context) def questionresponse = context.expand('${get ux survey question details questionid#responseasxml}') def idvals = questionresponse.split("<id>", -1) def choice1id = idvals[1].split("</id>", -1)[0] def choice4id = idvals[2].split("</id>", -1)[0] def prop2 = testrunner.testcase.testsuite.project.getproperty("positivesurveyanswer") prop2.setvalue(choice1id) def prop3 = testrunner.testcase.testsuite.project.getproperty("negativesurveyanswer") prop3.setvalue(choice4id) 
  3. with obtaining value , transferring project's properties, next test step then:

     {   "questionchoiceid" : ${#project#negativesurveyanswer},   "restaurantid" : ${create new restaurant#responseasxml#//*:id},   "alertprofileid" : ${#project#emailalertprofileid}  } 

hope helps others!


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -