Postman运行一次时其中的请求执行多次

发布时间 2023-12-21 11:16:50作者: wl夏白

背景

运行1次时,实现其中的几个请求执行多次,每次执行时的参数不同

方式

在要开始循环的请求中通过pm.environment.set('next', pm.info.requestId)将这个请求的id记下来
然后当要循环这个请求的的时候,先改变请求中的变量,然后再通过postman.setNextRequest跳转到要循环执行的请求,从而实现在一次运行中,1个请求不同的变量执行多次。记得最后需要跳出循环。

//pm.environment.set('next', pm.info.requestId)
postman.setNextRequest(pm.environment.get('next'));

官方文档
https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#skip-request-execution-from-pre-request-scripts