【问题标题】:Targeted Request in postman.setNextRequest() can't set Environment Variablespostman.setNextRequest() 中的目标请求无法设置环境变量
【发布时间】:2018-11-05 10:44:35
【问题描述】:

我使用postman.setNextRequest("login") 来调用登录请求。在登录测试中,我从令牌登录响应中设置环境变量。这行不通。登录测试成功,但环境变量token不存在。

集合中的预请求脚本:

var email = "foo@bar.com";
var password = "mypassword";
pm.environment.set("email", email); // success to set env variable
pm.environment.set("password", password); // success to set env variable
postman.setNextRequest("login");
postman.setNextRequest(null);

登录请求中的测试脚本:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
    var dt = pm.response.json();
    pm.environment.set("token", dt.token); // failed to set env variable
});

【问题讨论】:

  • 为什么脚本中有第二个SetNextRequest?如果您有一些东西可以在同一个地方结束流程,那么工作流程是否甚至使用第一个。签出点 2 getpostman.com/docs/v6/postman/scripts/branching_and_looping
  • 如果我没有在最后一个脚本中设置postman.setNextRequest(null);,登录请求将被不断调用。

标签: postman


【解决方案1】:

我通过在运行收集之前启用 Collection Runner 中的 Persist Variables 复选框来解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-20
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多