我正在使用 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/