【问题标题】:How to use a while loop when using Postman使用 Postman 时如何使用 while 循环
【发布时间】:2021-09-25 13:38:18
【问题描述】:

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

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

while i < 5
{
   "FirstName": "TestFN",
   "LastName": "TestLN",
   "orderID": *I want to update this based on the value of i --> "Concat(100,i)"*
}

【问题讨论】:

  • 我认为this 可以回答您的问题。

标签: loops while-loop postman


【解决方案1】:

在请求前添加:

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 或 collection runner 运行时,这将运行请求 5 次,就像评论中提到的 @Danny 一样

【讨论】:

  • 他们需要使用 Collection Runner 才能工作。看起来他们试图在单个请求中执行此操作,并期望它多次发送请求。
猜你喜欢
  • 2018-12-05
  • 1970-01-01
  • 2011-10-06
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 1970-01-01
  • 2020-05-04
相关资源
最近更新 更多