2
votes

Is there a way to use a wildcard inside an assertion in a XPath test with SoapUI?

I took a look at SoapUI's documentation and they say you can do something like this

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

I checked the 'Allow Wildcards' checkbox.

My question is : I want to assert my date starts with 2012-08-22 but i dont care about the minutes and seconds. I guess my the expression should be something like 2012-08-22* but it doesn't work.

2

2 Answers

3
votes

What you are doing sounds like it should work. Here is a quick example i cooked up using a rest service from http://www.geonames.org/export/web-services.html#timezone. I'm using the demo they have supplied

http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo output is

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

If you do an xpath match on the result and use the select from current button you get

//geonames/timezone/time

2012-07-25 04:39

If you update this to

//geonames/timezone/time

2012-07-25*

this will work fine and when updating the rest request with a new lat and lng the assertion will still pass since it is not checking the time. If this doesn't help, please supply your full assertion and maybe i could help more.

*note: for soap requests, make sure to declare the namespace and then use the proper format

//ns1:message
1
votes

It will be sort of a pain, but here is what you can do:

1) Figure out an Xpath 'base' using the assertion tab (sounds like you are here already). I used this public site to test against: http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl

I used the CornerPoints method with 'hawaii' as the single param.

I created this 'base' 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) Create a Properties step

3) Create a Property transfer step

4) Create a groovy script

5) add a property... i called mine misc

6) add a transfer step

* 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) Add something like this to your groovy script:

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

In the groovy step you can do anything you need to get at your (partial) data. The sample code I added gets lat/lons out of a long line wrapped in CDATA and then checks for just the starting part of some of the data.. just an example.

Remember that you can use groovy and java string methods:

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

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

More groovy tips: http://www.soapui.org/Scripting-Properties/tips-a-tricks.html