Hamcrest matchers json subarray: is there a way to use hasItems to look for items in a subarray? -
for example, had following json response:
{ "0": { "field1" : 5 "field2" : 10 } "1": { "field1" : 1 "field2" : 10 } }
is there way verify field1 has values 5 , 1? stuck @ .body statement here:
.body("[0].field1", matchers.hasitems(1));
it totally possible not understand hasitems supposed do, since tried lots of combinations of [0], [*], , field names , none of them work. wish there usage article hamcrest , json didn't cover basic cases. know if asking possible?
thanks reading.
first of "json document" not valid. should this:
{ "0": { "field1" : 5, "field2" : 10 }, "1": { "field1" : 1, "field2" : 10 } }
since you're targeting path matches single element should use equalto
(or is
) hamcrest matcher:
.body("0.field1", matchers.equalto(5));
please note rest assured not use "stefan goessner" jsonpath syntax. uses groovy gpath expression language.
Comments
Post a Comment