java - How to fetch JSON object from Json array in REstAssured -
can please me solve scenario:
i new restassured
, handling json
in our automation script. have api
response jsonarray
i.e.,
[{ "id": 1002, "entity": "testcase", "fieldname": "textname", "displayname": "name" }, { "id": 1003, "entity": "testcase", "fieldname": "steps", "displayname": "teststeps" }]
while automation, verification need fetch reponse. have tried below 1 not getting expected output
string api = "/field/entity/testcase" response response = given().auth().preemptive().basic("test.manager", "test.manager").when().get(api); jsonobject jsonresponsebody = new jsonobject(response.body().asstring()); assert.assertequals(jsonresponsebody.getstring("fieldname"), "textname");
and tried this:
jsonarray array = new jsonarray(); jsonobject jsonresponsebody = array.getjsonobject(0);
thanks inadvance
you should try this:
string api = "/field/entity/testcase" response response = given().auth().preemptive().basic("test.manager", "test.manager").when().get(api); jsonarray jsonresponsebody = new jsonarray(response.body().asstring()); assert.assertequals(jsonresponsebody.getjsonobject(0).getstring("fieldname"), "textname");
Comments
Post a Comment