2011-01-21 14 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を使用する前にデカールされます。

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> 
関連する問題