0
votes

In my SoapUI response I have a XML structure that repeats itself. For examples:

  <b:quote-data>
    <b:quote-data>
      <b:premium>4.66</b:premium>
    </b:quote-data>
    <b:quote-data>
      <b:premium>5.6</b:premium>
    </b:quote-data>
    <b:quote-data>
      <b:premium>7.58</b:premium>
    </b:quote-data>
  </b:quote-data>

I currently have the assertion which works to assert the value in the first premium field. I don't understand how to have multiple asserts to match all three fields.

// get the xml response
def response = messageExchange.getResponseContent() 
// parse it
def xml = new XmlSlurper().parseText(response)
// find your node by name
def node = xml.'**'.find { it.name() == 'premium' }
// assert 
assert node.toString().matches("4.66")

Is there a Way to skip over the first field to asset the second?

1

1 Answers

2
votes

Use findAll to get all 'premium' nodes and iterate over the node list:

    def nodelist = xml.'**'.findAll{ it.name() == 'premium' } 
    def assertions = [4.66, 5.6, 7.58]
    def i=0
    // assert  
    for (node in nodelist) assert node.toString().matches(assertions[i++].toString())