Forum Discussion

javiermartin's avatar
javiermartin
New Contributor
12 years ago

Assert xml empty-element

I need to assert by XPath match an empty xml element or a JSON respons without anything.

The xml tab shows this:
<Response xmlns="http://....................">
<booksNotRefunded/>
<booksRefunded>
<e>9788401383403</e>
</booksRefunded>
<email>xxxxxx@xxxxxxx.xxx</email>
</Response>


And JSON tab shows this:
{
"booksRefunded": ["9788401383403"],
"booksNotRefunded": [],
"email": "xxxxxx@xxxxxxx.xxx"
}


I want use 3 assertions:
1.- Response code 200. it's ok
2.- booksRefunded exists and has information
3.- booksNotRefunded exists and hasn't information (here is the problem, because i don't know how to do this XPath Match assertion)

Somebody can help me????

Thanks

2 Replies

  • SiKing's avatar
    SiKing
    Community Expert
    For empty elements you can use something like
    empty(//booksNotRefunded)
  • SiKing wrote:
    For empty elements you can use something like
    empty(//booksNotRefunded)


    I think that I have to write this in "Declare"....

    I supose in "Expected Result" I have to write "true"????

    In this case it works, but if I retry only this step, my xml changes to:
    <Response xmlns="http:..................">
    <booksNotRefunded>
    <e>9788468711157</e>
    </booksNotRefunded>
    <booksRefunded/>
    <email>xxxxxx@xxxxxx.xxx</email>
    </Response>


    Then, with empty(//booksNotRefunded) the assertion is ok in soapui, but it's not ok, because "booksNotRefunded" has a node ("<e>")