Reputation: 737
i'm running a postman test suit using newman api. Its executing properly as expected but i want to export environment variable generated during test execution in file, in command line it is possible using --export-environment:
newman run collectionPreReq.json -e Environment.json -k --export-environment newmanExport.json
for the same i'm writing javascript to get environment exported by collectionPreReq but not getting what i'm looking for, the code is
var newman = require('newman');
newman.run({
collection: require('./collectionPreReq.json'),
//reporters: 'cli',
environment: require('./Environment.json'),
insecure: true
}).on('start', function (err, args) {
console.log('running a collection...');
}).on('done', function (err, summary) {
if (err || summary.error) {
console.error('collection run encountered an error.');
}
else {
console.log('collection run completed.:');
console.log("summary environment :");
console.log(summary.environment);
}
});
Output:
running a collection...
collection run completed.:
summary environment :
{ object: [Function], toJSON: [Function] }
Upvotes: 1
Views: 6332
Reputation: 1
To console log the actual environment variables you'd need to stringify the JSON first: .....
.on('done', function (err, summary) {
if (err || summary.error) {
console.error('collection run encountered an error.');
}
else {
console.log('collection run completed.:');
console.log("summary environment :");
console.log(JSON.stringify(summary.environment))
}
});
Upvotes: 0
Reputation: 36
Please try to use this newman option exportEnvironment: require('./Environment.json') in the javascript file like
newman.run({
collection: require('./collectionPreReq.json'),
//reporters: 'cli',
environment: require('./Environment.json'),
exportEnvironment: require('./Environment.json'),
insecure: true
})....
Surely, This statement will work.
Upvotes: 2
Reputation: 1350
Not possible per NodeJS documentation.
The process.env property returns an object containing the user environment. See environ(7).
An example of this object looks like:
{
TERM: 'xterm-256color',
SHELL: '/usr/local/bin/bash',
USER: 'maciej',
PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
PWD: '/Users/maciej',
EDITOR: 'vim',
SHLVL: '1',
HOME: '/Users/maciej',
LOGNAME: 'maciej',
_: '/usr/local/bin/node'
}
It is possible to modify this object, but such modifications will not be reflected outside the Node.js process. In other words, the following example would not work:
$ node -e 'process.env.foo = "bar"' && echo $foo
Upvotes: 0