bars = xmlPath.g" /> bars = xmlPath.g" /> bars = xmlPath.g"/>

RestAssured Groovy gpath findAll returns a single value in case it finds only one match

475 Views Asked by At

Given an xml like

<foo>
 <bar>1</bar>
 <bar>2</bar>
</foo>

I would like to get all the values from a

String tagName = "bar"
List<Sting> bars = xmlPath.get(String.format("**.findAll {it.name() == '%s' }", tagName));

It is working when i have multiple bar nodes in the response xml. But when i got only one node then xmlPath.get("**.findAll....") returns only a single String value, and Java throws exception

Any idea how to tell Groovy "**.findAll...." to return List with one element in case there is only one match in the prediction?

1

There are 1 best solutions below

0
MiklosBalazsi On

It is working with getList()

String tagName = "bar"
List<Sting> bars = xmlPath.getList(String.format("**.findAll {it.name() == '%s' }", tagName));