Flo
Flo

Reputation: 335

Query Match in SoapUI doesn't work for a proper Xpath

So i got this XML:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
   <s:Header>
      <a:Action s:mustUnderstand="1">http://http://someurl.de/test/schema/function</a:Action>
      <a:MessageID>urn:uuid:4f318e88-c586-42c4-a2e8-2d9fdd18daca</a:MessageID>
      <a:ReplyTo>
         <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
      </a:ReplyTo>
      <a:To s:mustUnderstand="1">http://localhost:8088/mockMessageServiceViaWsHttpX509TokenWithoutSct</a:To>
   </s:Header>
   <s:Body>
      <ReceiveMessages xmlns="http://someurl.de/test/schema">
         <request xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <ServiceNameIdentifier>single</ServiceNameIdentifier>
            <ServiceNameQualifier/>
         </request>
      </ReceiveMessages>
   </s:Body>
</s:Envelope>

I used several XPath expressions so far like this one:

count(//ServiceNameIdentifier[.='single'])

or this

count(//ReceiveMessages/request/ServiceNameIdentifier[.='single'])

and i'm checking if that result is 1.

I checked this:

//ReceiveMessages/request/ServiceNameIdentifier/text()

and tested if the result is "single" but also to no avail....

At the site https://www.freeformatter.com/ it worked. In SoapUI it doesn't and i have no idea what i'm doing wrong...

Upvotes: 1

Views: 591

Answers (2)

craigcaulfield
craigcaulfield

Reputation: 3538

Namespaces always hurt my head, so I try to bypass them whenever possible. The following XPath uses local-name() to ignore the namespace of the elements, and the contains function to test for the contents:

count(//*[local-name() = 'ServiceNameIdentifier'][contains(.,'single')])

For your payload, this returns 1:

enter image description here

Upvotes: 2

Alexis
Alexis

Reputation: 463

You need to define and use namespaces, as shown here https://www.soapui.org/docs/functional-testing/point-and-click-testing/point-and-click-with-xpath.html

Upvotes: 0

Related Questions