jeudi 4 janvier 2018

Better way of comparing two JSON data in Automation Script

I am new to JBehave Rest automation script. Below I wrote few lines of code where my requirement is to compare each and every actual JSON field data with the expected data. Here the number of fields in JSON is huge how can i write the script in best way which will handle such scenario.

JSONObject actualjson = new JSONObject(actualJsonresponse);
JSONArray actualjsonData = actualjson.getJSONArray("outputDtlList");
JSONObject expectedjson = new JSONObject(RTRestServicesBean.getConfigurationJsonConfigValue());
JSONArray expectedjsonData = expectedjson.getJSONArray("outputDtlList");

String actual_storagetype = actualjsonData.getJSONObject(0).getString("storageType");
String expected_storagetype = expectedjsonData.getJSONObject(0).getString("storageType");

Assert.assertEquals(actual_storagetype, expected_storagetype);

String actual_locnNbr = actualjsonData.getJSONObject(0).getString("locnNbr");
String expected_locnNbr = expectedjsonData.getJSONObject(0).getString("locnNbr");

Assert.assertEquals(actual_locnNbr, expected_locnNbr);

Aucun commentaire:

Enregistrer un commentaire