如何在soapUI中添加多个断言

时间:2017-08-16 07:55:46

标签: soap groovy soapui

我想在soapUI中添加多个断言,就像在响应中一样:

  <ns0:Message>A</ns0:Message>

返回。我想添加“A”,“B”,“C”作为断言,以便如果返回任何值,则断言可以通过。谢谢!

 <soapenv:Body>
  <ns0:Fault xmlns:ns1="http://www.w3.org/2003/05/soap-envelope" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/">
     <faultcode>OSB-382500</faultcode>
     <faultstring>Mandatory Parameter Customer Type cannot be empty (uuid: 1f8b9637-11b1-47ea-9ebd-3abf2fda950e)</faultstring>
     <detail>
        <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">
           <ns6:Timestamp>2017-08-16T20:44:27.15+05:30</ns6:Timestamp>
           <ns6:ErrorCode>500</ns6:ErrorCode>
           <ns0:Name/>
           <ns0:Severity>Critical</ns0:Severity>
           <ns0:Category>Technical</ns0:Category>
           <ns0:ReasonCode>ReasonCode</ns0:ReasonCode>
           <ns0:Message>A</ns0:Message>
        </ns0:Fault>
     </detail>
  </ns0:Fault>
</soapenv:Body>

1 个答案:

答案 0 :(得分:3)

取样xml,因为你还没有提到任何数据。

在SoapUI中,您可以使用以下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}"

您可以使用示例xml快速找到在线 demo

请注意,示例xml显示断言错误,因为它具有除预期之外的其他值。