0

i have a request in soapui which returns a json response. i'm using groovy to retrieve the content of the response. response :

<item><response>{
  "timestamp": "2016-04-01T16:40:34",
  "data": [
    {
      "deleted_at": null,
      "userid": "b6d66002-8da4-4c03-928c-46871f084fb8",
      "updated_by": null,
      "created_at": "2016-03-01T16:40:34",
      "updated_at": "2016-03-01T16:40:34",
      "created_by": null,
      "value": "hBeO",
      "setting": "test",
      "name": "test2"
    }
  ],
  "success": true
}</response></item>

From this response i want to retrieve each node like: deleted_at created_at

so i use this groovy

import groovy.json.JsonSlurper

def response = context.expand( '${set_settings#Response#declare namespace ns1=\'https://wato.io/ns/20160131\'; //ns1:set_settings_resp[1]/ns1:item[1]/ns1:response[1]}' )
def slurper = new JsonSlurper()
def result = slurper.parseText(response)

testRunner.testCase.setPropertyValue("user_id", result.data.userid)

and i receive this error message:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlTestCasePro.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [userid, [b6df6662-8da4-4c03-928c-46871f084fb8]] Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String) error at line: 8

It works only for timestamp node. any help please. Thank you

1 Answer 1

2

It's because result.data is a list, so it returns a list (containing one item) for userid

You need to just get the first item from the list, so try:

testRunner.testCase.setPropertyValue("user_id", result.data.userid.head())
Sign up to request clarification or add additional context in comments.

1 Comment

now there is no error message but the result is null, it stores nothing in property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.