我正在使用Postman的打包应用程序版本来编写针对我的Rest API的测试。我正在尝试管理连续测试之间的状态。为了方便这一点,暴露给Javascript测试运行时的Postman对象具有用于设置变量的方法,但没有用于读取的方法。
postman.setEnvironmentVariable("key", value );
现在,我可以在下一次调用中通过{{key}}结构读取此值,该结构从当前环境中吸入值。但是,这在测试中不起作用;它只在请求构建内容中起作用。
那么,有没有办法从测试中读到这些东西呢?
发布于 2014-03-11 04:36:25
根据文档中的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;
https://stackoverflow.com/questions/21418529
复制相似问题