应用程序中使用的所有api都有一个公共端点:https://m.companyname.com/application/svcwebservice.php
json具有嵌套数组,响应如下所示:
[{
"usertype": [{
"id": "1",
"type": "Service Manager (Admin)",
"description": "Service Manager (Admin)"
}, {
"id": "2",
"type": "Customer Relations Executive",
"description": "Customer Relations Executive"
}, {
"id": "3",
"type": "Service Advisor",
"description": "Service Advisor"
}, {
"id": "4",
"type": "Accountant (Admin)",
"description": "Accountant (Admin)"
}, {
"id": "5",
"type": "Technician\/Mechanic",
"description": "Technician\/Mechanic"
}, {
"id": "6",
"type": "Sales Manager (Admin)",
"description": "Sales Manager (Admin)"
}, {
"id": "7",
"type": "Sales Consultant",
"description": "Sales Consultant"
}, {
"id": "8",
"type": "Receptionist",
"description": "Receptionist"
}, {
"id": "9",
"type": "Implant (Admin)",
"description": "Implant (Admin)"
}, {
"id": "10",
"type": "Vice President \/ General Manager - Sales (Admin)",
"description": "Vice President \/ General Manager - Sales (Admin)"
}, {
"id": "11",
"type": "Group Manager (Admin)",
"description": "Group Manager (Admin)"
}, {
"id": "13",
"type": "Coordinator",
"description": "Coordinator"
}, {
"id": "14",
"type": "Customer Relations Manager (Admin)",
"description": "Customer Relations Manager (Admin)"
}, {
"id": "15",
"type": "Receptionist",
"description": "Receptionist"
}, {
"id": "16",
"type": "Vice President \/ General Manager - Service (Admin)",
"description": "Vice President \/ General Manager - Service (Admin)"
}, {
"id": "17",
"type": "Principal (Admin)",
"description": "Principal (Admin)"
}, {
"id": "18",
"type": "CEO (Admin)",
"description": "CEO (Admin)"
}, {
"id": "19",
"type": "COO (Admin)",
"description": "COO (Admin)"
}, {
"id": "20",
"type": "Insurane Admin",
"description": "Insurane Admin"
}]
}]
有效负载为:requesttype:“ getusertypes”
相同的api端点对另一个有效负载给出以下响应:
[{
"cards": [{
"average_inv_amount": "26",
"on_time_checkin": "100.00%",
"ontime_pickup_percentage": "81.89%",
"average_distance": "5.5",
"cust_rating": "4.2",
"total_vehicle": "4"
}]
}, {
"pickup_details": [{
"name": "Awaiting",
"value": "0"
}, {
"name": "Active Pickup",
"value": "1"
}, {
"name": "Not Checked in",
"value": "0"
}, {
"name": "Checked In",
"value": "0"
}, {
"name": "Picked Up Today",
"value": "1"
}]
}, {
"drop_details": [{
"name": "Awaiting",
"value": "0"
}, {
"name": "To Service Centre",
"value": "0"
}, {
"name": "To Customer",
"value": "0"
}, {
"name": "Active Dropoff ",
"value": "0"
}, {
"name": "Delivered Today",
"value": "0"
}]
}, {
"notification": [{
"queue_paused_pickup": "0",
"queue_paused_dropoff": "0",
"not_checkedin": "1",
"queue_cancelled": "2",
"queue_rescheduled": "0",
"queue_mishaps": "0"
}]
}, {
"prepaid": [{
"pre_paid": "-250",
"credit_limit": "10000",
"show_add_credit": "1",
"allow_booking": "1"
}]
}]
以此类推。
问题:
我应该如何使用邮递员对此进行测试?
答案 0 :(得分:0)
这取决于您要测试的内容。
首先使用
var jsonData = pm.response.json();
您可以通过像这样的索引来访问它们
pm.test("Your test name", function() {
var jsonData = pm.response.json();
//For Entry 4
pm.expect(jsonData[0].usertype[3].id).to.eql("4");
pm.expect(jsonData[0].usertype[3].type).to.eql("Accountant (Admin)");
pm.expect(jsonData[0].usertype[3].description).to.eql("Accountant (Admin)");
});
或使用for循环遍历它们。但这取决于您的测试用例。