How to read environment variables in Postman tests?

I am using the Postman version of batch applications to write tests against my Rest API. I am trying to manage the state between successive trials. To facilitate this, the Postman object, subject to Javascript testing, has methods for setting variables, but is not used for reading.

postman.setEnvironmentVariable("key", value ); 

Now I can read this value in the next call using the {{key}} structure, which sucks values ​​from the current environment. BUT, this does not work in tests; it only works in the request enclosure.

So, is there anyway to read this material from the tests?

+46
rest testing postman
Jan 28 '14 at 22:45
source share
1 answer

According to the docs here you can use

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

to access them.

t

 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; 
+72
Mar 10 '14 at 20:36
source share



All Articles