Forum Discussion

groovynoob's avatar
groovynoob
Occasional Contributor
13 years ago

Property transfer, groovy script & parsing JSON response!

Hey folks!

I am relatively new to SoapUI as well as Groovy. I have a little bit of Java experience (in relation to Android), so while I'm not a complete noob, I'm not an expert in any of those realsm - which brings me here.

Problem: I am attempting to take a JSON response, parse through that response and return the value of a particular map element (I think this is the correct syntax?). Example response:

{"addUsersToDirectoryResponse":{"addUserToDirectoryResponse":[{"ack":"Success","userId":"2745379"}]}}


Here, I am trying to grab the userId and pass that back to a userId Property Transfer, so that other SoapUI testcases can reference that userId. Seems pretty simple, but I am completely lost. What I have so far is:


import groovy.json.JsonSlurper

def xresponse = testRunner.testCase.testSteps["addUserToDirectory"].testRequest.response.contentAsString
def slurper = new JsonSlurper()
def result = slurper.parseText(xresponse)

def addUserToDirectoryResponse = result.addUsersToDirectoryResponse.addUserToDirectoryResponse[0].userId


When I execute this, it returns me the userId. My question is: how do I pass that on to a property transfer, which would then pass it on to a custom property of a testsuite?

Can anyone point me in the right direction? Thanks!

2 Replies

  • groovynoob's avatar
    groovynoob
    Occasional Contributor
    Also, I just discovered I could configure the Property Transfer to Get Data -> getuserId step -> property result. However, when I run that Property Transfer step, it comes back with [error: Unexpected element: CDATA].
  • groovynoob's avatar
    groovynoob
    Occasional Contributor
    I figured it out. Someone pointed me towards setPropertyValue and I was able to make this work completely. I added the following line and was able to set a custom property with the value I needed to transfer:

    testRunner.testCase.testSuite.setPropertyValue("userIdResponse", addUserToDirectoryResponse)



    TIA!