Coding / Programming Videos

Post your favorite coding videos and share them with others!

SoapUI Beginner Tutorial 17 – How to create Script Assertions

Download Video link >



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

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

Bookmark(0)
 

 

View Comments source >

Transcript view all >

00:00 hello and welcome to this session on so

00:03 py beginner tutorial and today we are

00:06 going to learn about script assertions

00:08 in so py and we will see what is a

00:11 script assertion how do we add script

Leave a Reply

Please Login to comment
  Subscribe  
Notify of
Translate »