Home Business Analyst BA Agile Coach SoapUI Beginner Tutorial 17 – How to create Script Assertions

SoapUI Beginner Tutorial 17 – How to create Script Assertions

9
0



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

Previous articleBritain's Got Talent 2016 Kathleen Jenkins Semi-Final Round 1 Full Performance S10E08
Next articleAWS Certification Guide

LEAVE A REPLY

Please enter your comment!
Please enter your name here