有没有办法在XPath测试中使用通配符来进行断言呢?我查看了SoapUI的文档,他们说你可以这样做:
<path1>
<path2>*</path2>
</path1>
我勾选了“允许通配符”复选框。
我的问题是:我想要断言我的日期以2012-08-22开始,但对分钟和秒数不在意。我猜想我的表达式应该是类似于2012-08-22*,但它不起作用。
<geonames>
<timezone tzversion="tzdata2012c">
<countryCode>AT</countryCode>
<countryName>Austria</countryName>
<lat>47.01</lat>
<lng>10.2</lng>
<timezoneId>Europe/Vienna</timezoneId>
<dstOffset>2.0</dstOffset>
<gmtOffset>1.0</gmtOffset>
<rawOffset>1.0</rawOffset>
<time>2012-07-25 04:39</time>
<sunrise>2012-07-25 05:50</sunrise>
<sunset>2012-07-25 21:00</sunset>
</timezone>
</geonames>
//ns1:message
这可能有点麻烦,但以下是您可以做的:
1)使用断言选项卡找出Xpath“基础”(听起来您已经在此处)。我使用了此公共网站进行测试:http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl
我使用CornerPoints方法,并将'hawaii'作为单个参数。
我创建了此“基础”Xpath:
declare namespace ns1='http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl';
declare namespace SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/';
declare namespace SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/';
/SOAP-ENV:Envelope/SOAP-ENV:Body/ns1:CornerPointsResponse/listLatLonOut
(it will write the declare statements for you if you click declare)
(which you can test out in the assertions window)
2) 创建一个属性步骤
3) 创建一个属性传输步骤
4) 创建一个Groovy脚本
5) 添加一个属性...我称之为misc
6) 添加一个传输步骤
* transfer from the CornerPoints - Request 1 --- Response
* paste the Xpath stuff in the box under the 'transfer from'
* Transfer to your property
(You can test with the little play button)
7) 在您的Groovy脚本中添加类似以下内容:
def x = context.expand( '${Properties#misc}' )
def parts = x.tokenize(',')
for (def part in parts)
{
log.info(part)
if (part.startsWith("-153"))
log.info("good")
}
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html
更多Groovy技巧: http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
XPathContains comparaison failed, expecting [2012-08-25*], actual was [2012-08-25T00:00:00-04:00]
。 - Gab