首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SoapUI-如何从响应中断言

SoapUI-如何从响应中断言
EN

Stack Overflow用户
提问于 2011-01-21 17:40:27
回答 1查看 7.8K关注 0票数 2

我是SoapUI的新手,我有一个基本问题。当我得到对服务的响应时,我想为一个值做一个断言。下面是我在Script Assertion下创建的脚本

代码语言:javascript
复制
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 com.eviware.soapui.support.XmlHolder@8b6500 (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 | | | | groovy.util.slurpersupport.NodeChildren@17a5c01 (toString() == "") | | | groovy.util.slurpersupport.NoChildren@2e80e1 (toString() == "") | | groovy.util.slurpersupport.NodeChildren@10f682f (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>
EN

回答 1

Stack Overflow用户

发布于 2011-01-24 16:44:16

找到了解决方案。命名空间在使用getNodeValue之前进行了反序列化。

代码语言:javascript
复制
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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4757299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档