pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
pm.test(“Array should contain objects as value”, function () {
var responseData = pm.response.json();
if(typeof responseData === ‘object’&& responseData.length>0){
for(i=0;i<responseData.length;i++){
if( typeof responseData[i] === 'object'){
var abc = Object.keys(responseData[i]).length;
if(abc<=12){
if(responseData[i].hasOwnProperty("id")){
pm.expect(responseData[i].id).to.satisfy(Number.isInteger,"invalid DataType : DataType of id should be integer " +"at index position "+i);
pm.expect(responseData[i].id).to.be.within(1000,100000 , " length of the id is invalid at index position "+i);
if(responseData[i].hasOwnProperty("primary_camera")){
pm.expect(responseData[i].primary_camera).to.be.a('String',"invalid DataType : DataType of primary_camera should be String" +"at index position "+i );
pm.expect(responseData[i].primary_camera).to.have.lengthOf.above(0," length of primary_camera is invalid at index position "+i);
pm.expect(responseData[i].primary_camera).to.have.lengthOf.below(101," length of primary_camera is invalid at index position "+i);
if(responseData[i].hasOwnProperty("textlong")){
pm.expect(responseData[i].textlong).to.be.a('String',"invalid DataType : DataType of textlong should be String" +"at index position "+i);
pm.expect(responseData[i].textlong).to.have.lengthOf.above(-1,"length of textlong is invalid at index position "+i);
pm.expect(responseData[i].textlong).to.have.lengthOf.below(101,"length of textlong is invalid at index position "+i);
if(responseData[i].hasOwnProperty("gps_points")){
if(typeof responseData[i].gps_points === 'object'){
var gpslen = responseData[i].gps_points.length;
for(j=0;j<gpslen;j++){
if(typeof responseData[i].gps_points[j]==='object'){
var gpsobjkey = Object.keys(responseData[i].gps_points[j]).length;
if(gpsobjkey<=2){
if(responseData[i].gps_points[j].hasOwnProperty("lat"))
{ pm.expect(responseData[i].gps_points[j].lat).to.be.a('Number', "invalid datatype : type of lat should be string at index position" +i);
if(responseData[i].gps_points[j].hasOwnProperty("lng")){
pm.expect(responseData[i].gps_points[j].lng).to.be.a('Number', "invalid datatype : type of lat should be string at index position" +i);}
else{
pm.expect.fail("****lng is missing**** at index positon "+i +" and gps_points index position "+j);
}
}
else{
pm.expect.fail("****lat is missing**** at index positon "+i +" and gps_points index position "+j );
}
}
else{pm.expect.fail("invalid entry: at index positioni of gps_points "+j+" and at index position of responseData "+i);}
}
else{pm.expect.fail("invalid data :gps_points propeties should be objects at gps_points obj position "+j+"and at responseData index position "+i);}
}
}
else{ pm.expect.fail("gps point should be array at index position "+i)}
if(responseData[i].hasOwnProperty("bkcolor")){
pm.expect(responseData[i].bkcolor).to.be.a('String',"invalid DataType : DataType of bkcolor should be String"+"at index position "+i );
pm.expect(responseData[i].bkcolor).to.have.lengthOf.above(-1," length of bkcolor is invalid at index position "+i);
pm.expect(responseData[i].bkcolor).to.have.lengthOf.below(101," length of bkcolor is invalid at index position "+i);
if(responseData[i].hasOwnProperty("image")){
pm.expect(responseData[i].image).to.be.a('String',"invalid DataType : DataType of image should be String" +"at index position "+i);
pm.expect(responseData[i].image).to.have.lengthOf.above(-1," length of image is invalid at index position "+i);
pm.expect(responseData[i].image).to.have.lengthOf.below(101," length of image is invalid at index position "+i);
if(responseData[i].hasOwnProperty("type")){
pm.expect(responseData[i].type).to.be.a('String',"invalid DataType : DataType of type should be String"+"at index position "+i );
pm.expect(responseData[i].type).to.have.lengthOf.above(-1,"length of type is invalid at index position "+i);
pm.expect(responseData[i].type).to.have.lengthOf.below(101," length of type is invalid at index position "+i);
if(responseData[i].hasOwnProperty("textshort")){
pm.expect(responseData[i].textshort).to.be.a('String',"invalid DataType : DataType of textshort should be String"+"at index position "+i );
pm.expect(responseData[i].textshort).to.have.lengthOf.above(-1," length of textshort is invalid at index position "+i);
pm.expect(responseData[i].textshort).to.have.lengthOf.below(101," length of textshort is invalid at index position "+i);
if(responseData[i].hasOwnProperty("cam_id_and_area")){
if(typeof responseData[i].cam_id_and_area === 'object'){
var cam_area_len = responseData[i].cam_id_and_area.length;
for(j=0;j<cam_area_len;j++){
if(typeof responseData[i].cam_id_and_area[j]==='object'){
var cam_objkey = Object.keys(responseData[i].cam_id_and_area[j]).length;
if(cam_objkey<=2){
if(responseData[i].cam_id_and_area[j].hasOwnProperty("id")){
pm.expect(responseData[i].cam_id_and_area[j].id).to.be.a('String', "invalid datatype : type of lat should be string at index position" +i);
if(responseData[i].cam_id_and_area[j].hasOwnProperty("area")){
pm.expect(responseData[i].cam_id_and_area[j].area).to.be.a('Number', "invalid datatype : type of lat should be string at index position" +i);
}
else{pm.expect.fail("**area of cam_id_and_area is missing at position "+j+"at responseData object position "+i)}
}
else{pm.expect.fail("**id of cam_id_and_area is missing at position "+j+"at responseData object position "+i)}
}
else{pm.expect.fail("invalid entry: at index positioni of cam_id_and_area "+j+" and at index position of responseData "+i);}
}
else{pm.expect.fail("cam_id_and_area should contain values as object at cam_id_and_area index position "+j+" and at responseData index position "+i);}
}
}
else{pm.expect.fail("cam_id_and_area should be array of objects at index position "+i);}
if(responseData[i].hasOwnProperty("txtcolor")){
pm.expect(responseData[i].txtcolor).to.be.a('String',"invalid DataType : DataType of txtcolor should be String"+"at index position "+i );
pm.expect(responseData[i].txtcolor).to.have.lengthOf.above(-1,"length of txtcolor is invalid at index position "+i);
pm.expect(responseData[i].txtcolor).to.have.lengthOf.below(101,"length of txtcolor is invalid at index position "+i);
if(responseData[i].hasOwnProperty("area"))
{
pm.expect(responseData[i].area).to.be.a('String',"invalid DataType : DataType of area should be String"+"at index position "+i );
pm.expect(responseData[i].area).to.have.lengthOf.above(0," length of area is invalid at index position "+i);
pm.expect(responseData[i].area).to.have.lengthOf.below(101,"length of area is invalid at index position "+i);
if(responseData[i].hasOwnProperty("spotType")){
pm.expect(responseData[i].spotType).to.be.a('String',"invalid DataType : DataType of spotType should be String " +" at index position "+i);
pm.expect(responseData[i].spotType).to.have.lengthOf.above(-1,"length of spotType is invalid at index position "+i);
pm.expect(responseData[i].spotType).to.have.lengthOf.below(101,"length of spotType is invalid at index position "+i);
}
else{
pm.expect.fail("****spotType is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****area is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****txtcolor is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****cam_id_and_area is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****textshort is missing**** at index position "+i)
}
}
else{
pm.expect.fail("****type is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****image is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****bkcolor is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****gps_points is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****textlong is missing**** at index position "+i);
}
}
else{
pm.expect.fail("****primary_camera is missing**** at index position "+i);
}
}
else{
if(responseData[i].id){
pm.expect.fail("id is missing"+responseData[i].id);
}
else{
pm.expect.fail("****id is missing**** at object position "+i);
}
}
}
else{
pm.expect.fail("invalid data entry: length should not be greater than 12 at index position "+i);
}
}
else{
pm.expect.fail("invalid data:" +responseData[i]+" must be in the form of objects at index position "+i);
}
}
}
else{
pm.expect.fail(responseData+" must be array of objects");
}
});
dataset
[
{
"id": 1000,
"primary_camera": "JFCC01",
"textlong": "",
"gps_points": [
{
"lat": 45.543983,
"lng": -122.961816
},
{
"lat": 45.543983,
"lng": -122.961898
},
{
"lat": 45.544008,
"lng": -122.961899
},
{
"lat": 45.544008,
"lng": -122.961817
}
],
"bkcolor": "",
"image": "",
"type": "normal_right",
"textshort": "",
"cam_id_and_area": [
{
"id": "JFCC01",
"area": 170000
},
{
"id": "JFCC02",
"area": 25000
},
{
"id": "MANUAL",
"area": 25000
}
],
"txtcolor": "",
"area": "D1",
"spotType": "Staff"
},
{
"id": 1001,
"primary_camera": "JFCC01",
"textlong": "",
"gps_points": [
{
"lat": 45.544008,
"lng": -122.961817
},
{
"lat": 45.544008,
"lng": -122.961899
},
{
"lat": 45.544032,
"lng": -122.961899
},
{
"lat": 45.544032,
"lng": -122.961817
}
],
"bkcolor": "",
"image": "",
"type": "normal_right",
"textshort": "",
"cam_id_and_area": [
{
"id": "JFCC01",
"area": 170000
},
{
"id": "JFCC02",
"area": 25000
},
{
"id": "MANUAL",
"area": 25000
}
],
"txtcolor": "",
"area": "D1",
"spotType": "Staff"
},
{
"id": 1002,
"primary_camera": "JFCC01",
"textlong": "",
"gps_points": [
{
"lat": 45.544032,
"lng": -122.961817
},
{
"lat": 45.544032,
"lng": -122.961899
},
{
"lat": 45.544057,
"lng": -122.9619
},
{
"lat": 45.544057,
"lng": -122.961818
}
],
"bkcolor": "",
"image": "",
"type": "normal_right",
"textshort": "",
"cam_id_and_area": [
{
"id": "JFCC01",
"area": 170000
},
{
"id": "JFCC02",
"area": 25000
},
{
"id": "MANUAL",
"area": 25000
}
],
"txtcolor": "",
"area": "D1",
"spotType": "Staff"
},
{
"id": 1003,
"primary_camera": "JFCC01",
"textlong": "",
"gps_points": [
{
"lat": 45.544057,
"lng": -122.961818
},
{
"lat": 45.544057,
"lng": -122.9619
},
{
"lat": 45.544082,
"lng": -122.961901
},
{
"lat": 45.544082,
"lng": -122.961819
}
],
"bkcolor": "",
"image": "",
"type": "normal_right",
"textshort": "",
"cam_id_and_area": [
{
"id": "JFCC01",
"area": 170000
},
{
"id": "JFCC02",
"area": 25000
},
{
"id": "MANUAL",
"area": 25000
}
],
"txtcolor": "",
"area": "D1",
"spotType": "Staff"
},
{
"id": 1004,
"primary_camera": "JFCC01",
"textlong": "",
"gps_points": [
{
"lat": 45.544082,
"lng": -122.961819
},
{
"lat": 45.544082,
"lng": -122.961901
},
{
"lat": 45.544106,
"lng": -122.961902
},
{
"lat": 45.544106,
"lng": -122.96182
}
],
"bkcolor": "",
"image": "",
"type": "normal_right",
"textshort": "",
"cam_id_and_area": [
{
"id": "JFCC01",
"area": 170000
},
{
"id": "JFCC02",
"area": 25000
},
{
"id": "MANUAL",
"area": 25000
}
],
"txtcolor": "",
"area": "D1",
"spotType": "Staff"
}
]
for example: in array of objects suppose id is not there or extra filed is there as per class is there . for example instead od id its cid,or instead of primarycamera its primarycameras , so it should tell me that in this obect primarycameras is wrong or cid is wrong , please help me to find solution