Postman 邮递员:全局变量存储为字符串?

Postman 邮递员:全局变量存储为字符串?,postman,Postman,{{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.

{{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;

为了在测试窗口中获取全局变量,应该使用“postman.getGlobalVariable()”函数

在您的情况下,应该是这样的:


测试[“产品ID”]=jsonData.productId==postman.getGlobalVariable(“产品ID 1”)

肯定有:看看这里。我在这里发布之前已经测试了上面的代码。你是对的,对此表示抱歉。请更新你的答案,这样我就可以投票了,否则它不会让我这么做。