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
log.info messageExchange.getEndpoint()

//check for TimeTaken
log.info messageExchange.getTimeTaken()

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

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

//validate response nodes
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( 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
log.info json.name
assert json.capital.toString() != null
assert json.name.toString() == “[Taiwan]”

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

__________________________________________________________

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

SOAPUI PLAYLIST

YOUTUBE PLAYLIST
https://www.youtube.com/channel/UCTt7pyY-o0eltq14glaG5dg/playlists

YOUTUBE
https://www.youtube.com/automationstepbystep

FACEBOOK
https://www.facebook.com/automationstepbystep

TWITTER
https://twitter.com/automationsbs

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 – http://automationstepbystep.com/

source

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

    {
    "Memberpersonaldeatils":{
    "Person":
    {
    "Personname":
    }}}

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

  6. Json Assertion groovy script doesnt workk …i copied line by line your code but it says after executing
    ""assert json.name.toString() == "[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(AntlrParserPlugin.java:143) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111) 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...