Forum Discussion

prouser's avatar
prouser
Contributor
12 years ago

Xpathassert-DateElement exists in all abbreviatedList nodes?

Hi All

I am trying validate via xpath assertion that "TBC_DATE" element exists in all abbreviatedList nodes

Soap UI Response::
<Results>
<ns2:abbreviatedList>
<ns2:id>4723278</ns2:id>
<ns2:TBC_DATE>2013-02-01</ns2:TBC_DATE>
<ns2:amount currency="USD">35.46</ns2:amount>
<ns2:cardLastFour>XXXXXXXXXXXX0316</ns2:cardLastFour>
</ns2:abbreviatedList>
...
...
...
...
...
...
...
...
<ns2:abbreviatedList>
<ns2:id>4723279</ns2:id>
<ns2:TBC_DATE>2013-02-01</ns2:TBC_DATE>
<ns2:amount currency="USD">37.46</ns2:amount>
<ns2:cardLastFour>XXXXXXXXXXXX0319</ns2:cardLastFour>
</ns2:abbreviatedList>
</Results>

Xpath Assertion
exists(//ns2:Row/ns2:TBC_DATE/text())

Correct me if Im wrong,
I am hoping that the above validation should return
true:: if TBC_DATE element exists in descendants of all <ns2:abbreviatedList> nodes
false::if TBC_DATE element is missing in even one of the descendants of <ns2:abbreviatedList> nodes

Currently, it is returning true even though TBC_DATE is missing in some of the <ns2:abbreviatedList> nodes

3 Replies

  • SiKing's avatar
    SiKing
    Community Expert
    You are wrong! XPath matches only the first occurrence.

    You could try something like this:
    count(//*:abbreviatedList) = count(//*:TBC_DATE)
    should return "true".
  • Thankyou

    Could you tell why it is just only one 'equal to' operator for comparing the counts
    In groovy script, I know that we have to use two 'equal to' operators for comparision

    Could you also provide me links to any documentation where I can learn to write these xpath assertions more effectively