gpt4 book ai didi

javascript - 如何正确使用 postman 测试api响应中的对象总和

转载 作者:行者123 更新时间:2023-11-28 21:07:52 24 4
gpt4 key购买 nike

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

以下示例的响应仅包含 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

我创建了一个 postman 测试,无论我输入哪个值,它都会通过,所以如果响应返回 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;

最佳答案

您只使用了一个 =你的意思是两个。这意味着您正在尝试分配长度。

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

关于javascript - 如何正确使用 postman 测试api响应中的对象总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50939996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com