I'm using the packaged app version of Postman to write tests against my Rest API. I'm trying to manage state between consecutive tests. To faciliate this, the Postman object exposed to the Javascript test runtime has methods for setting variables, but none for reading.
postman.setEnvironmentVariable("key", value );
Now, I can read this value in the next call via the {{key}} structure that sucks values in from the current environment. BUT, this doesn't work in the tests; it only works in the request building stuff.
So, is there away to read this stuff from the tests?
Variables quick start Add a variable named my_variable and give it an initial value of Hello . Save, then close the environment tab. Open a new request tab and enter https://postman-echo.com/get?var={{my_variable}} as the URL. Hover over the variable name to inspect the variable's value and scope.
To set up Postman environment variables:In the top right corner of Postman, click the environment selector and select Manage environments. Click Add to add a new environment where you'll define your OneLogin environment variables. Note: You'll need to use your API credentials to generate the access_token value.
Step1 − Add the below script to get the value of the Environment variable tutorial and print it in console. Step2 − Click on Send to execute a request. Step3 − After the Response is received, open the Postman Console. It displays postman which is the value set for the Environment variable tutorial.
Postman can import and export Postman data, including collections, environments, data dumps, and globals. Postman can also import non-Postman data in the form of API schemas to help you consolidate your API development workflow.
According to the docs here you can use
environment["foo"] OR environment.foo globals["bar"] OR globals.bar
to access them.
ie;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With