2011-01-21 92 views
2

我是SoapUI的新手我有一個基本問題。當我得到一個服務的迴應時,我想爲一個價值做一個斷言。下面是我在腳本聲明下創建的腳本SoapUI-如何從響應中斷言

import com.eviware.soapui.support.XmlHolder 

def holder = new XmlHolder(messageExchange.responseContentAsXml) 
assert holder["//ConstraintId[0]"] =="5000006"; 

I get the following error: 
assert holder["//ConstraintId[0]"] =="5000006" | | | | [] false [email protected] (toString() threw java.lang.NullPointerException) 

********************************************************** 
import org.xml.sax.helpers.DefaultHandler 

def rootNode = new XmlSlurper().parseText(messageExchange.responseContentAsXml) 
assert rootNode.Body.Constraintid[0].text=="5000006"; 

I get the following error: 
assert rootNode.Body.Constraintid[0].text=="5000006" | | | | | | | | | | | false | | | | [email protected] (toString() == "") | | | [email protected] (toString() == "") | | [email protected] (toString() == "") | 

Response 
    <soap:Body> 
     <GetEnumResponse xmlns="http://www.xyz.com/"> 
     <GetEnumResult> 
      <ErrorCode>0</ErrorCode> 
      <StatusId>0</StatusId> 
     </GetEnumResult> 
     <enumsInformation> 
      <EnumInformation> 
       <TransactionId>0</TransactionId> 
       <ConstraintId>5000006</ConstraintId> 
       <EnumValue>abc</EnumValue> 
       <Index>10</Index> 
      </EnumInformation> 
     </enumsInformation> 
     </GetEnumResponse> 
    </soap:Body> 

回答

2

能夠找到解決方案。命名空間在使用getNodeValue之前進行decalared。

import com.eviware.soapui.support.XmlHolder 
def holder = new XmlHolder(messageExchange.responseContentAsXml) 

holder.namespaces["tal"]="http://www.xyz.com/" 
def node = holder.getNodeValue("//tal:ConstraintId[1]"); 
log.info(node); 
assert node == "5000006"; 

<soap:Body> 
     <GetEnumResponse xmlns="http://www.xyz.com/"> 
     <GetEnumResult> 
      <ErrorCode>0</ErrorCode> 
      <StatusId>0</StatusId> 
     </GetEnumResult> 
     <enumsInformation> 
      <EnumInformation> 
       <TransactionId>0</TransactionId> 
       <ConstraintId>5000006</ConstraintId> 
       <EnumValue>xyz</EnumValue> 
       <Index>10</Index> 
      </EnumInformation> 
     </enumsInformation> 
     </GetEnumResponse> 
    </soap:Body> 
相關問題