Forum Discussion

mamar's avatar
mamar
Contributor
12 years ago

How to check non existence of a xml element?

Hi.
I have a scenario which i need to validate particular xml element is not returned in the response. Below is my general response.

<Transaction>
-----<Code>7019</Code>
-----<Type>Debit</Type>
<Transaction>

For one of my test case it will return as below.

<Transaction>
-----<Code>7019</Code>
<Transaction>

Here i need to check whether the <Type> element is not exist in my response. Could any help me how to validate through Groovy?
  • SiKing's avatar
    SiKing
    Community Expert
    XPath:
    exists(//*:Type)

    Groovy:

    def responseType = context.expand( '${#Response//*:Type}' )
    assert responseType.isEmpty()