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] }
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.