rest - 如何在 Postman 测试中读取环境变量?

标签 rest testing postman

我正在使用 Postman 的打包应用程序版本针对我的 Rest API 编写测试。我正在尝试管理连续测试之间的状态。为了促进这一点,暴露给 Javascript 测试运行时的 Postman 对象具有设置变量的方法,但没有用于读取的方法。

postman.setEnvironmentVariable("key", value );

现在,我可以通过从当前环境中吸取值的 {{key}} 结构在下一次调用中读取该值。但是,这在测试中不起作用;它只适用于请求构建的东西。

那么,是否可以从测试中读取这些内容?

最佳答案

根据文档 here你可以使用

environment["foo"] OR environment.foo
globals["bar"] OR globals.bar

访问它们。

即;

postman.setEnvironmentVariable("foo", "bar");

tests["environment var foo = bar"] = environment.foo === "bar";

postman.setGlobalVariable("foobar", "1");

tests["global var foobar = true"] = globals.foobar == true;

postman.setGlobalVariable("bar", "0");

tests["global var bar = false"] = globals.bar == false;

关于rest - 如何在 Postman 测试中读取环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21418529/

相关文章:

java - 使用 Spring 在 Java 中发送文本 REST 消息

java - 使用 Spark Java 通过 http 流式传输视频文件

javascript - ESLint "code"与可修复的 "whitespace"值

javascript - 如何将 html 表单发布请求翻译成 Postman

java - Spring Autowired 和 Builder 注释

rest - 基于 token 的 REST API 身份验证

ruby-on-rails - 晒干萝卜步骤定义

django - 如何知道何时使用 django-nose 运行测试

python - 如何在 Nginx 中故意引发 400 Bad Request?

rest - Sharepoint _api/contextinfo 失败,401 Unauthorized using PostMan