groovynoob
13 years agoOccasional Contributor
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:
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!
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!
