首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用Postman时如何使用while循环

在使用Postman时如何使用while循环
EN

Stack Overflow用户
提问于 2021-07-17 03:15:44
回答 1查看 291关注 0票数 1

我正在尝试使用Postman来验证API。我可以没有任何问题地验证单个请求,并获得所需的输出。但是,我现在想做一个负载测试,并运行相同的调用5次。

我尝试使用for和while循环,但Postman给出了一个错误。

代码语言:javascript
复制
while i < 5
{
   "FirstName": "TestFN",
   "LastName": "TestLN",
   "orderID": *I want to update this based on the value of i --> "Concat(100,i)"*
}
EN

回答 1

Stack Overflow用户

发布于 2021-07-17 05:30:06

在前置请求中添加:

代码语言:javascript
复制
let count = pm.variables.get("count") ? pm.variables.get("count") : 5

if(count-1){
   count -= 1
   postman.setNextRequest(pm.info.requestName)
   pm.variables.set("count",count)
}else{
  // if you don't want to execute remaining
  //postman.setNextRequest(null)
}

当使用newman或集合运行器运行时,这将运行请求5次,如注释中提到的@Danny

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68414253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档