断言具有相同路径的多个字段

Assert multiple fields with the same path

在我的 SoapUI 响应中,我有一个重复自身的 XML 结构。例如:

  <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>

我目前有断言,可以断言第一个高级字段中的值。我不明白如何有多个断言来匹配所有三个字段。

// 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")

有没有办法跳过第一个字段来资产第二个字段?

使用findAll获取所有'premium'个节点并遍历节点列表:

    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())