【发布时间】:2019-09-03 01:36:08
【问题描述】:
我正在使用 Postman 对使用 CSV 文件作为外部文件数据的 API 运行测试。在 CSV 文件中,有多个数据集,数据量不同,有的有数据,有的没有。当我运行 collection runner 并运行第一个数据集时,它会失败,因为有尚未定义的变量并且 API 会引发数据错误。
在 CSV 中
-
数据集 1
- 订购, 客户编号, 条码 1, 数量 1, 单价 1
-
数据集 2
- 订购, 客户编号, 条码 1, 数量 1, 单价 1, 条码 2, 数量 2, 单价2
-
数据集 3
- 订购, 客户编号, 条码 1, 数量 1, 单价 1, 条码 2, 数量 2, 单价 2, 条码 3, 数量 3, 单价 3
In the body I've added that extra variables in case it is available in a data set.
{
"order" : "{{orderId}}",
"clientId" : "{{clientId}}",
"skus" : [
{
"barcode": {{barcode1}},
"quantity": {{quantity1}},
"unitPrice": {{price1}}
},
{
"barcode": {{barcode2}},
"quantity": {{quantity2}},
"unitPrice": {{price2}}
},
{
"barcode": {{barcode3}},
"quantity": {{quantity3}},
"unitPrice": {{price3}}
}
]
}
这是回复:
{
"order" : "1000305408",
"clientId" : "30",
"skus" : [
{
"barcode": 123123123,
"quantity": 1,
"unitPrice": 100
},
{
"barcode": {{barcode2}},
"quantity": {{quantity2}},
"unitPrice": {{price2}}
}
]
}
有没有办法阻止那些未定义的变量键和数据,同时仍将其保留在正文中,以防万一新数据集具有变量?
【问题讨论】:
-
这个问题比这里发布的 99.9% 的问题都要好。
-
哈哈感谢编辑!
标签: javascript json postman