2017-08-16 35 views
0

要添加多個斷言在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> 
+0

你的意思是標籤可以有A,B,C作爲值? – Rao

+0

是的正確.... – Abhishek

+0

請檢查答案,看看是否有幫助。 – Rao

回答

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顯示聲明錯誤,因爲它具有比預期的其他值。

+0

我試過了,但它傳遞的是所有的值。 – Abhishek

+0

@Abhishek,你見過演示和斷言錯誤嗎?你有沒有修改上述腳本?你介意顯示你使用過的數據嗎? – Rao

+0

我已經爲你編輯了這個問題 – Abhishek

相關問題