如何在 soapUI 中添加多个断言
How to add multiple assertions in soapUI
我想在 soapUI 中添加多个断言,例如 if 在响应中:
<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>
抽样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 显示断言错误,因为它具有与预期不同的值。
我想在 soapUI 中添加多个断言,例如 if 在响应中:
<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>
抽样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 显示断言错误,因为它具有与预期不同的值。