I'm using SoapUI Pro 4.5.0 and also a beginner for this tool. I need to get the value from the response (JSON format). Can anyone give me sample code for this?
Note: I'm using the REST based service not SOAP based service.
I'm using SoapUI Pro 4.5.0 and also a beginner for this tool. I need to get the value from the response (JSON format). Can anyone give me sample code for this?
Note: I'm using the REST based service not SOAP based service.
SoapUI includes JsonSlurper class in the groovy jar, so you just have to import it like
import groovy.json.JsonSlurper
and then the response is obtained as
responseContent = testRunner.testCase.getTestStepByName("<test_step_name>").getPropertyValue("Response")
jsonresponse = new JsonSlurper().parseTest(responseContent)
Now you can access the elements in response like
jsonresponse.id
I would suggest using JSONPath from a Groovy script. You may need to add the JSONPath Jar to the /bin/ext directory.
I don't have SoapUI in front of me, but in the groovy script it would be something like:
def getResponse = context.expand( '${SomeGet#response}' )
def jsonSuff = JsonPath.read(getResponse, "\$..*")
Here is what was in my POM if you have trouble with the other JAR (I had created an external JAR that I used in SoapUI).
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.8.1</version>
</dependency>
And this was my import statement: import com.jayway.jsonpath.JsonPath