如何正确使用Postman测试api响应中的对象总数

时间:2018-06-20 03:58:39

标签: javascript api testing postman qa

我一直在尝试测试或弄清楚如何创建一个邮递员测试,该测试基本上会根据返回视频对象的次数通过/桶测试。

以下示例中的响应仅包含1个视频对象(返回的对象很多)

{
"message": "OK",
"results": {
    "videoList": [
        {
            "date": 1529005027860,
            "reference": "00000163-daf7-d2a1-ad6f-faff8e490000",
            "topicPath": "/data/sales-series/2013/art-of-the-automobile",
            "brightcoveId": "5783291272001",
            "image": {
                "imagePathLarge": "http://qa2.sothebys.psdops.com/dims4/default/871ac2f/2147483647/resize/2000x2000%3E/quality/90/?url=https%3A%2F%2Fsothebys-brightspot-lower.s3.amazonaws.com%2F01%2F50%2F7a814bf44bf4b8fcbc0151540a74%2F34e50f06adc442efb9e2119d1d09a9f5%2Fposter.jpg",
                "imagePathSmall": "http://qa2.sothebys.psdops.com/dims4/default/1ba20a8/2147483647/resize/250x250%3E/quality/90/?url=https%3A%2F%2Fsothebys-brightspot-lower.s3.amazonaws.com%2F01%2F50%2F7a814bf44bf4b8fcbc0151540a74%2F34e50f06adc442efb9e2119d1d09a9f5%2Fposter.jpg",
                "alt": "[Geneva] Important Watches",
                "imagePathMedium": "http://qa2.sothebys.psdops.com/dims4/default/4f630f7/2147483647/resize/600x600%3E/quality/90/?url=https%3A%2F%2Fsothebys-brightspot-lower.s3.amazonaws.com%2F01%2F50%2F7a814bf44bf4b8fcbc0151540a74%2F34e50f06adc442efb9e2119d1d09a9f5%2Fposter.jpg",
                "fileReference": "00000164-19c9-da7f-af6f-ddd9a6650000"
            },
            "dateDisplay": "2018-06-14T15:37:07.860-0400",
            "sortOrder": 1529005027860,
            "topic": "Art of the Automobile",
            "text": "description value in the description field ",
            "title": "[Geneva] Important Watches",
            "objectType": "VIDEO"
        },

]
},
"errors": [],
"statusCode": 200

我创建了一个邮递员测试,无论我输入哪个值都可以通过,因此如果响应返回3个视频,则下面的测试仍然通过,请提供一些帮助!

var response = JSON.parse(responseBody);
var video = response.results.videoList[0]

//Testing Video Count

tests["5 video objects returned"] = response.results.videoList.length = 5;

1 个答案:

答案 0 :(得分:2)

您仅使用一个=,意思是两个。这意味着您正在尝试分配长度。

// This checks the length of an array is equal to 5
response.results.videoList.length == 5;