邮递员 - 同一迭代中的 API 个请求中的 运行 个选择性请求
Postman - Selective run of API Requests within the same Iteration
我有一组 API 请求(保存在同一文件夹下)。我需要根据 Runner 中指定的迭代次数多次执行这些操作。
但是有一个(第一个)请求只需要为整个 运行 执行一次。该请求为收集auth-token的认证请求。
即我有 Req1、Req2、Req3、Req4、保存在同一个collection/folder下。我需要 运行 这组 100 次迭代。但是 Req1 应该只 运行 一次,而 Req2, Req3 和 Req4应该全部执行100次。
有没有办法告诉 Postman(或以其他方式设置)在请求开始时只执行 Req1一次 整个运行?
Postman 具有构建工作流功能,您可以在其中指定接下来要调用的请求。
到达Req4后,根据计数器调用Req1之后的Req2。
这可以在邮递员请求 window.
的 Tests
选项卡中实现
Pseudo code -
set 2 global/environment variables , iteration = <some number you need>, iteration_ref = 0
<In Req1 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req2')
<In Req2 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req3')
<In Req3 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req4')
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
或者仅在最后一个请求中,如果您对集合中设置的请求顺序非常有信心。
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
确保您首先在集合中有 Req1(Post Request),在集合运行器中有 only 1 iteration
。我们正在使用 global/env 变量进行迭代。
PS: 我强烈推荐有一个简单的 python 或 js 脚本使用请求库来调用 API,上面的流程是一个机智的 hack。
参考 - https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/
我有一组 API 请求(保存在同一文件夹下)。我需要根据 Runner 中指定的迭代次数多次执行这些操作。 但是有一个(第一个)请求只需要为整个 运行 执行一次。该请求为收集auth-token的认证请求。
即我有 Req1、Req2、Req3、Req4、保存在同一个collection/folder下。我需要 运行 这组 100 次迭代。但是 Req1 应该只 运行 一次,而 Req2, Req3 和 Req4应该全部执行100次。
有没有办法告诉 Postman(或以其他方式设置)在请求开始时只执行 Req1一次 整个运行?
Postman 具有构建工作流功能,您可以在其中指定接下来要调用的请求。
到达Req4后,根据计数器调用Req1之后的Req2。 这可以在邮递员请求 window.
的Tests
选项卡中实现
Pseudo code -
set 2 global/environment variables , iteration = <some number you need>, iteration_ref = 0
<In Req1 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req2')
<In Req2 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req3')
<In Req3 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
postman.setNextRequest('Req4')
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
或者仅在最后一个请求中,如果您对集合中设置的请求顺序非常有信心。
<In Req4 window>
if(pm.globals.get("iteration_ref") < pm.globals.get("iteration")-1)
{
postman.setGlobalVariable("iteration_ref",
Number(postman.getGlobalVariable("iteration_ref"))+1);
postman.setNextRequest('Req2')
}
确保您首先在集合中有 Req1(Post Request),在集合运行器中有 only 1 iteration
。我们正在使用 global/env 变量进行迭代。
PS: 我强烈推荐有一个简单的 python 或 js 脚本使用请求库来调用 API,上面的流程是一个机智的 hack。
参考 - https://learning.getpostman.com/docs/postman/collection_runs/building_workflows/