如何在SoapUI中通过groovy检查请求值



我有一个简单的模拟服务,请求如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fa1="http://TargetNamespace.com/FA1">
<soapenv:Header/>
<soapenv:Body>
<fa1:items>
<fa1:itemname>logo</fa1:itemname>
<fa1:price></fa1:price>
<fa1:vat>10</fa1:vat>
<fa1:description>nové logo</fa1:description>
</fa1:items>
</soapenv:Body>
</soapenv:Envelope>

我已经使用脚本来控制响应值。一开始XmlHolder不起作用。所以我用了

def req = mockRequest.getContentElement().execQuery("/")
def records = new XmlParser(false, false).parseText(req[0].xmlText())

以获取请求并将其解析为节点。

{http://TargetNamespace.com/FA1}items[attributes={}; value=[
{http://TargetNamespace.com/FA1}itemname[attributes={}; value=[logo]], 
{http://TargetNamespace.com/FA1}price[attributes={}; value=[1]], 
{http://TargetNamespace.com/FA1}vat[attributes={}; value=[10]], 
{http://TargetNamespace.com/FA1}description[attributes={}; value=[nové logo]]]
]

但我无法获得价格价值。我试过

def price = records.price.text()

表达式records.find( { it.text() == "1"} )返回{http://TargetNamespace.com/FA1}price[attributes={}; value=[1]]但是类似CCD_ 3的CCD_。

关键是使用def records = new XmlParser(错误,错误).parseText(req[0].xmlText())

这带来了这样的请求值:

fa1:items[attributes={xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/, xmlns:fa1=http://TargetNamespace.com/FA1}; value=[
fa1:itemname[attributes={}; value=[logo]], 
fa1:price[attributes={}; value=[1]], 
fa1:vat[attributes={}; value=[10]], 
fa1:description[attributes={}; value=[nové logo]]]
]

然后您可以通过名称namespace:name读取值,因此records.find( { it.name() == "fa1:price"} ).text()返回1

最新更新