0
{{productId1}}
等于1邮差:全局变量存储为字符串?
这是请求:
localhost:9000/test/product/{{productId1}}
它的工作原理,并返回我:
{
"productId": 1,
"title": "Hat X",
"description": "This is Hat X."
}
但是,它不是测试:
var jsonData = JSON.parse(responseBody);
tests["Status code is 200"] = responseCode.code === 200;
tests["Product ID"] = jsonData.productId === "{{productId1}}";
tests["Title"] = jsonData.title === "Hat X";
tests["Description"] = jsonData.description === "This is Hat X.";
第三行保持失败。到底是怎么回事?是否因为productId1
被读为字符串?如果是这样,我试图解析它为整数,没有运气。我怎样才能通过它而不失去这种类型?
我想:
tests["Product ID"] = jsonData.productId === "{{productId1}}";
tests["Product ID"] = jsonData.productId === "{{$productId1}}";
tests["Product ID"] = jsonData.productId === {{productId1}};
tests["Product ID"] = jsonData.productId === productId1;
邮差根本没有这样的功能! –
绝对有:看看这里。 https://docs.omniref.com/js/npm/newman/1.1.4/symbols/postman.getGlobalVariable在发布之前,我已经测试了上面的代码。 –
你是对的,对不起。请更新您的答案,以便我可以放弃它,否则它不会让我这样做。 –