2

有没有办法在使用 SoapUI 的 XPath 测试中的断言中使用通配符?

我看了一下 SoapUI 的文档,他们说你可以做这样的事情

<path1>
  <path2>*</path2>
</path1>

我选中了“允许通配符”复选框。

我的问题是:我想断言我的日期从 2012-08-22 开始,但我不在乎分钟和秒。我想我的表达应该类似于 2012-08-22* 但它不起作用。

4

2 回答 2

3

您正在做的事情听起来应该可行。这是我使用来自http://www.geonames.org/export/web-services.html#timezone的休息服务制作的一个简单示例。我正在使用他们提供的演示

http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo 输出是

<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>

如果您对结果进行 xpath 匹配并使用从当前按钮中选择,您将获得

//地名/时区/时间

2012-07-25 04:39

如果您将其更新为

//地名/时区/时间

2012-07-25*

这将正常工作,并且当使用新的 lat 和 lng 更新其余请求时,断言仍然会通过,因为它没有检查时间。如果这没有帮助,请提供您的完整断言,也许我可以提供更多帮助。

*注意:对于soap请求,请确保声明命名空间,然后使用正确的格式

//ns1:message
于 2012-07-25T02:56:59.403 回答
1

这会有点痛苦,但这是你可以做的:

1) 使用断言选项卡找出一个 Xpath 'base'(听起来你已经在这里了)。我使用这个公共站点进行测试: 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)添加一个属性...我叫我的杂项

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")
}

在常规步骤中,您可以做任何需要获取(部分)数据的事情。我添加的示例代码从包含在 CDATA 中的长行中获取纬度/经度,然后仅检查某些数据的起始部分.. 只是一个示例。

请记住,您可以使用 groovy 和 java 字符串方法:

http://groovy.codehaus.org/groovy-jdk/java/lang/String.html

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html

更多常规技巧: http: //www.soapui.org/Scripting-Properties/tips-a-tricks.html

于 2012-07-24T23:09:27.097 回答