[英]How to check request value by groovy in SoapUI
I have simple mock service with request like this:我有一个简单的模拟服务,请求如下:
<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>
I have used script to control response value.我使用脚本来控制响应值。 At the start XmlHolder didn't work.
一开始 XmlHolder 不起作用。 So I used
所以我用
def req = mockRequest.getContentElement().execQuery("/")
def records = new XmlParser(false, false).parseText(req[0].xmlText())
to get request and parse it into nodes.获取请求并将其解析为节点。
{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]]]
]
But I cannot get price value.但我无法获得价格价值。 I have tried
我试过了
def price = records.price.text()
Expression records.find( { it.text() == "1"} )
returns {http://TargetNamespace.com/FA1}price[attributes={}; value=[1]]
表达式
records.find( { it.text() == "1"} )
返回{http://TargetNamespace.com/FA1}price[attributes={}; value=[1]]
{http://TargetNamespace.com/FA1}price[attributes={}; value=[1]]
but records.find( { it.name() == "price"} )
alike records.find( { it.name() == "{http://TargetNamespace.com/FA1}price"} )
returns null. {http://TargetNamespace.com/FA1}price[attributes={}; value=[1]]
但records.find( { it.name() == "price"} )
类似records.find( { it.name() == "{http://TargetNamespace.com/FA1}price"} )
返回空值。
The key is use def records = new XmlParser(
false, false ).parseText(req[0].xmlText())
关键是使用
def records = new XmlParser(
false, false ).parseText(req[0].xmlText())
That brings request value like this:这带来了这样的请求值:
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]]]
]
Then you can read value by name namespace:name
so records.find( { it.name() == "fa1:price"} ).text()
returns 1然后你可以通过名称
namespace:name
读取值namespace:name
so records.find( { it.name() == "fa1:price"} ).text()
返回1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.