Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am trying to create a groovy script assertion in SoapUI. In the response, I and trying to pull a field called written. however there are +15 of these fields.

I is possible to add the XPath to the XmlSlurper to find the exact written fields I want to assert against.

Looking at the XML response below, I would like to assert the value in b:premium\written. not the one from the b:other. Given there are 15+ b:written fields i would like to assert the value using the xpath.

XML Response:

<s:Body>
    <NewRateResponse>
        <NewRateResult>
            <b:policies>
                 <b:other>
                     <b:written>00.00</b:written>
                 </b:other>
                 <b:premium>
                     <b:written>31.21</b:written>
                 </b:premium>
            </b:policies>
        </NewRateResult>
    </NewRateResponse>
</s:Body>

Assertion Code:

import org.junit.Assert
def response = messageExchange.getResponseContent()
def xml = new XmlSlurper().parseText(response)
def nodePremium = xml.'**'.find { it.name() == 'written'}
Assert.assertEquals(00.01, nodePremium.toDouble(),0)

I believe the area we need to change is def nodePremium = xml.'**'.find { it.name() == 'written'}. to be something like def nodePremium = xml.'**'.find { it.name() == 'premium\written'} but that does not work for me.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.