Abhishek Abhishek - 2 years ago 125
Groovy Question

How to add multiple assertions in soapUI

I want to add multiple assertions in soapUI, like if in response:


is returned. I want to add, "A", "B", "C" as assertions, so that if any of the values is returned, the assertion could Pass. Thanks!

<ns0:Fault xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/">
<faultstring>Mandatory Parameter Customer Type cannot be empty (uuid: 1f8b9637-11b1-47ea-9ebd-3abf2fda950e)</faultstring>
<ns0:Fault xmlns:ns0="http://group.vodafone.com/contract/vfo/fault/v1" xmlns:ns2="http://group.vodafone.com/contract/vho/header/v1" xmlns:ns3="http://group.vodafone.com/schema/common/v1" xmlns:ns6="http://docs.oasis-open.org/wsrf/bf-2" xmlns:ns7="http://www.w3.org/2005/08/addressing">

Rao Rao
Answer Source

Taking a sample xml, since you haven't mentioned any data.

In SoapUI, you can use below Script Assertion:

assert context.response, 'Response is empty or null'  

//Define or change for the assertion
def validValues = ['Tag': ['A', 'B', 'C']]
def tagToFind = 'Tag'

def pxml = new XmlSlurper().parseText(context.response)

//Find all the tag values and filter those are not in valid values
def result = pxml.'**'.findAll{it.name() == tagToFind &&  !(it.text() in validValues[tagToFind])}
assert !result, "Elements ${tagToFind} have different values other than valid- ${result}"

You can find the online demo quickly with sample xml.

Note that, the sample xml shows assertion error as it has other values than expected.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download