java1977
java1977

Reputation: 398

SoapUI how to check the count of number of items returned in response

is there is way to check the count of the items returned. basically I have a soap service which can return list of data items, is there an easy way to have an assert statement to check the count of the list? tried groovy script but didn't have much luck

Upvotes: 1

Views: 14462

Answers (2)

nwill001
nwill001

Reputation: 745

Yes. You can create a XPath Match assertion. Use the count() function.

There is a website that is a nice reference for all the XPath functions: http://zvon.org/comp/r/ref-XPath_2.html#Functions~count

Upvotes: 1

albciff
albciff

Reputation: 18507

You can add and assertion of XPath Match type in your testStep, and there check the condition. i.e you have a response similar to:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
      <myRoot xmlns:nt="http://mynamespace/">
        <list>
            <element>data1</element>
            <element>data2</element>
            <element>data3</element>
        </list>
      </myRoot>
   </soapenv:Body>
</soapenv:Envelope>

enter image description here

Then add in your assertion the next XPath count(//*:myRoot/*:list/*:element) and set the expected result, in this case 3:

enter image description here

Hope this helps,

Upvotes: 5

Related Questions