Script Assertions in SoapUI

SoapUI uses XPath to manipulate XML. But we cannot use XPath expressions on JSON.
But soapUI have capability to convert JSON to XML.
Only difference is that instead of using Response property you have to use ResponseAsXml property.
ResponseAsXml in soapUI will convert JSON to XML.
The best and easy way to assert on a JSON response is to use a Groovy Script Assertion
Now lets see how to use Script Assertion on a JSON reponse.

"Token":    {
      "UserId": "",
      "TimeStamp": "31/12/2014",
      "SignedInAs": "test"

The following is the script we can use to assert the content of the above Json response

import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response
assert json.Token.UserId = ""
assert json.Token.TimeStamp == "31/12/2014"
assert json.Token.SignedInAs == "test"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s