Postman:有没有办法将带有动态迭代编号的变量传递给请求?
摘要: 第一邮递员请求 - 测试选项卡:
let iterationCount = pm.info.iteration+1;
console.log(iterationCount);
const response = pm.response.json();
pm.environment.set(`location_${iterationCount}`, response.label);
第二邮递员请求
"CalibrationMask":
{
"Length": {{location_${iterationCount}}},
"Width": 0,
"Id": "3fc388275b724e82819cf44603db69c3"
}
当我将上述变量传递给第二个Postman请求时,它不起作用。我在这里想念什么?语法在请求中不正确?请建议
这里的要求是从每次迭代的第一响应中获取值,并将其存储为环境变量 例如:location_1,location_2,location_3,然后将此值传递给同一集合中的后续请求
Snippet:
1st Postman Request - Tests Tab:
let iterationCount = pm.info.iteration+1;
console.log(iterationCount);
const response = pm.response.json();
pm.environment.set(`location_${iterationCount}`, response.label);
2nd Postman Request
"CalibrationMask":
{
"Length": {{location_${iterationCount}}},
"Width": 0,
"Id": "3fc388275b724e82819cf44603db69c3"
}
When I pass the above variable to 2nd postman request, it doesn't work. What am i missing here? Syntax is incorrect in request? Please suggest
Requirement here is to fetch a value from 1st response for each iteration and store it as environment variable
For eg: Location_1, Location_2 , Location_3 and pass this value to subsequent requests in the same collection
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将两个请求都放在预定脚本中的A中。对于实际请求,请使用示例获取API请求。
Put both the requests within the pre-request script in a for loop; for the actual request, use a sample get api request.