HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

SoapUI Beginner Tutorial 17 - How to create Script Assertions

32,655 views November 13, 2018 17:41

Watch on YouTube
ChannelAutomation Step by Step - Raghav Pal

Description from the creator

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.com/playlist?list=PLhW3qG5bs-L-Bt9T_bny…

YOUTUBE PLAYLIST
youtube.com/channel/UCTt7pyY-o0eltq14glaG5dg/pl…


YOUTUBE
youtube.com/automationstepbystep

FACEBOOK
facebook.com/automationstepbystep

TWITTER
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 - automationstepbystep.com/

About this tutorial

Automation Step by Step - Raghav Pal published this 17:41 video tutorial on November 13, 2018. It has been watched 32,655 times on YouTube.

Category
Education
Duration
17:41
Published
November 13, 2018
Views
32,655
Likes
205

Tags

Share

This tutorial in other languages