SoapUI Beginner Tutorial 17 - How to create Script Assertions

Today we will learn:

1. What is Script Assertion
2. How to add Script Assertion
3. Different assertion scripts for xml and json messages
4. Tips and Tricks

Script assertion works on the last reponse received in soapui
works with messageExchange object
(messageExchange object stores all the details of the last request and response)

Script Assertion samples

//check response time
assert messageExchange.timeTaken 4000

//check for Endpoint messageExchange.getEndpoint()

//check for TimeTaken messageExchange.getTimeTaken()

//check for header (messageExchange.responseHeaders[“Content-Length”])
assert messageExchange.responseHeaders[“Content-Length”] != null

//check attachments
assert messageExchange.responseAttachments.length == 0 (messageExchange.responseAttachments.length)

//validate response nodes
def groovyUtils = new context )
def requsetHolder = groovyUtils.getXmlHolder( messageExchange.requestContent )
def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def refNum = responseHolder.getNodeValue(“//m:CountryCurrencyResult/m:sName”)
assert responseHolder.getNodeValue(“//m:CountryCurrencyResult/m:sName”) == “Rupees”

//to get response
def resp = messageExchange.responseContentAsXml.toString()

For JSON response

//get json response
import groovy.json.JsonSlurper
def responseMessage = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(responseMessage)

//assert node values
assert != null
assert == “[Taiwan]”

testStepName = get the Test Step Name testStepName
xmlHold = messageExchange.responseContentAsXml.toString() //to store the response as Xml string


#SoapUIScriptAssertions #SoapUIBeginnerTutorials #SoapUITraining #SoapUIBasics #SoapUIAPITesting #ApiTestingWithSoapUI #LearnSoapUI #SoapUIAssertions #SoapUIProject #SoapUITutorials






If you like videos on the channel Automation Step by Step, hit the like button and share with others.

Click the SUBSCRIBE button and hit the bell icon to keep getting new videos.

________ ONLINE COURSES TO LEARN ________

Visit –


20 thoughts on “SoapUI Beginner Tutorial 17 – How to create Script Assertions”
  1. Hi…How to add assertion for Response header value existence..i need to verify if a new header "Content-Language:en-US" is coming in soap response header

  2. Sir Who will provide the script ? Shall the testers need to write orelse dev provide ?

  3. Hi Raghav,very good explanation.all your videos are very good including selenium..i want to know how can we write a particular asserted json value into Excel sheet when we use Rest services..can u please let me know

  4. Hi Raghav,
    Thanks for the assertion video. Can you please help if json response needs to be validated and node values are more than 2 or so. These node values just need be validated with true or false like


  5. Hi Raghav
    Thanks for these wonderful videos. Is there a way to see all the functions in the package?

  6. Json Assertion groovy script doesnt workk …i copied line by line your code but it says after executing
    ""assert == "[ca]" | | | | | | | false | | [null, null] | [null, null]…"

  7. Hi Raghav, thanks for this video , can you also add videos to add assertions by JDBC and validate the response to JDBC by queries

  8. Hi Raghav , thanks for the tutorial series , i am getting compilation errors while running the "assert messageExchange.timeTaken 4000" in my groovy script : org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 1: unexpected token: 4000 @ line 1, column 35. assert messageExchange.timeTaken 4000 ^ org.codehaus.groovy.syntax.SyntaxException: unexpected token: 4000 @ line 1, column 35. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST( at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST( at ….

  9. How can I read and print "Name" text not it's value from the given example in above video? I have response in json, Thanks

  10. Hi Raghav, I have the schema in the form of JSON format(not as url), how can I validate schema in JSON format in Ready API. Please reply.

Leave a Reply

Your email address will not be published.

Captcha loading...