total / count items from list json response
15,041
Solution 1
I got answer to my question.
here is the code for rest assured
expect().body("final_list.findall.size()",equalTo(2)).when().get("/list.json);
thanks
Solution 2
if you expect final_list
to have 2 elements, you can use the hasSize()
matcher:
expect().body("final_list", hasSize(2)).when().get("/list.json);
I found this in the list of matchers from the Matchers class Java doc:
Solution 3
Yo can do the following:
jp = new JsonPath(response.asString());
String numFromsResponse = jp.get("final list.id.size()").toString();
Related videos on Youtube
Author by
dileepvarma
Updated on June 04, 2022Comments
-
dileepvarma almost 2 years
im trying to get count / total number of records from list api using Restassured.
Please share thoughts on how can we get it.
ex:
{ "final list": [ { "id": 123, "name": "sachin" }, { "id": 234, "name": "sourav" } ] }
I am expecting total as 2 here. please suggest.
-
Hussain Akhtar Wahid 'Ghouri' almost 11 yearsjsonObject.length , how about that ???
-
dileepvarma almost 11 yearspls tell me in restassured code
-
-
dileepvarma almost 11 yearshi anand.. im verifying response data using junit and i wanted to test number of records in the list json response
-
Kai Carver about 10 yearsa slightly simpler solution is: expect().body("final_list", hasSize(2)).when().get("/list.json);