newman -v):@Sripathi1983 There are two parts to handling this:
Ensure that environment values are updated to their desired values using postman.setEnvironmentVariable("var_name", "var_value");, or postman.setGlobalVariable in your collection request test scripts, where applicable.
To update the environment / globals file, you can use --export-environment / --export-globals, like so:
newman run coll.json -e env.json -g globals.json --export-environment env.json --export-globals globals.json
Thanks it worked for me
@Sripathi1983 That's great! Happy developing :smile:
thank you it work for me too ! 馃憤
@kunagpal And what about that when using newman with node.js please ? I cannot find a solution....
@tegomass You'll have to use the export options, like so:
newman.run({
collection: '/path/to/collection.json',
exportEnvironment: '/path/to/new/file.json',
exportGlobals: '/path/to/some/other/file.json'
}, function (err, summary) {
// change the world here...
})
Tested and worked. Awesome, thank you !
PS: @kunagpal : Is the exportEnvironment done after the entire collection run ?
Example, I want to reuse the {{sessionId}} which is set in the request1 (in the "Tests" tab) through :
postman.setEnvironmentVariable("sessionId", '1234');
But when I get the value in the 'beforeRequest' event :
newman.run({
collection: '/path/to/collection.json',
exportEnvironment: '/path/to/new/file.json',
exportGlobals: '/path/to/some/other/file.json'
}, function (err, summary) {
// change the world here...
}).on('beforeRequest', function(err, args) {
if (args.item.name === 'request2') {
const sid = require('/path/to/new/file.json').values[0].value;
console.log(sid);
}
})
The console.log(sid) displays the old value and not the new one updated in the request1.
My question is, is it possible to do the exportEnvironment after each request ? If no, is there another solution for my needs please ?
Thanks again ! :)
For my application, what I do is that i parse the "args" and modify it as I want.
Tested and worked. Awesome, thank you !
PS: @kunagpal : Is the exportEnvironment done after the entire collection run ?
Example, I want to reuse the {{sessionId}} which is set in the request1 (in the "Tests" tab) through :
postman.setEnvironmentVariable("sessionId", '1234');But when I get the value in the 'beforeRequest' event :
newman.run({ collection: '/path/to/collection.json', exportEnvironment: '/path/to/new/file.json', exportGlobals: '/path/to/some/other/file.json' }, function (err, summary) { // change the world here... }).on('beforeRequest', function(err, args) { if (args.item.name === 'request2') { const sid = require('/path/to/new/file.json').values[0].value; console.log(sid); } })The console.log(sid) displays the old value and not the new one updated in the request1.
My question is, is it possible to do the exportEnvironment after each request ? If no, is there another solution for my needs please ?
Thanks again ! :)
Hey @tegomass ,
Did you end up solving this? I am stuck n the same problem.
Thanks
@Sripathi1983 There are two parts to handling this:
- Ensure that environment values are updated to their desired values using
postman.setEnvironmentVariable("var_name", "var_value");, orpostman.setGlobalVariablein your collection request test scripts, where applicable.- To update the environment / globals file, you can use
--export-environment/--export-globals, like so:newman run coll.json -e env.json -g globals.json --export-environment env.json --export-globals globals.json
@kunagpal "Not All Heroes Wear Capes" Thanks It worked for me.
What about if you're using newman to point to an environment variable file hosted at https://api.getpostman.com?
Tested and worked. Awesome, thank you !
PS: @kunagpal : Is the exportEnvironment done after the entire collection run ?
Example, I want to reuse the {{sessionId}} which is set in the request1 (in the "Tests" tab) through :
postman.setEnvironmentVariable("sessionId", '1234');But when I get the value in the 'beforeRequest' event :
newman.run({ collection: '/path/to/collection.json', exportEnvironment: '/path/to/new/file.json', exportGlobals: '/path/to/some/other/file.json' }, function (err, summary) { // change the world here... }).on('beforeRequest', function(err, args) { if (args.item.name === 'request2') { const sid = require('/path/to/new/file.json').values[0].value; console.log(sid); } })The console.log(sid) displays the old value and not the new one updated in the request1.
My question is, is it possible to do the exportEnvironment after each request ? If no, is there another solution for my needs please ?
Thanks again ! :)
@kunagpal , can you please give the solution for this?
is, is it possible to do the export environment after each request? If no, is there another solution for my needs, please?
I want my env var file should get updated after each request and use the same in the upcoming request.
Kindly help me with this...
TIA.
i need solution for this too
is, is it possible to do the export environment after each request? If no, is there another solution for my needs, please?
I want my env var file should get updated after each request and use the same in the upcoming request.Kindly help me with this...
TIA.
The only workaround I found was to unset the variable in the pre-request or test tab.
pm.variables.unset("variableName");
Most helpful comment
@Sripathi1983 There are two parts to handling this:
Ensure that environment values are updated to their desired values using
postman.setEnvironmentVariable("var_name", "var_value");, orpostman.setGlobalVariablein your collection request test scripts, where applicable.To update the environment / globals file, you can use
--export-environment/--export-globals, like so: