Forum Discussion

SmartBear217's avatar
SmartBear217
Contributor
5 years ago
Solved

How do I verify that multiple values are all the same for an unknown amount of values?

I have some XML and want to verify the name column all contain the same name. There may be 1 row or there may be 20 rows. There is no way to know how many there will be. How do I verify the name o...
  • SmartBear217's avatar
    SmartBear217
    5 years ago

    Absolutely. Here's the way I did it in a groovy script assertion. First I retrieved the XML into an array and then looped through the array to verify each one. And that seems to be the problem with a regular Xpath assertion which is that I couldn't figure out how to loop through an unknown amount of values.

     

    import com.eviware.soapui.support.XmlHolder

    def holder = new XmlHolder(messageExchange.responseContentAsXml)

     

    def resultsArray = holder.getNodeValues("<XPATH GOES HERE>")

     

    //Loop array and verify what you need
    resultsArray .each{
    assert "${it}" == "<insert assertion string>"
    }