In Newman used as package how to retrieve an environment variable during the iteration?

@aurelien.lair Variables are accessible in script, prerequest, and, test events as well.
Refer the below snippet:

newman.run({
    collection: {
        item: {
            request: 'http://postman-echo.com/get',
            event: [{
                listen: 'test',
                script: 'pm.environment.set("resp", pm.response.json());'
            }]
        }
    },
    reporters: ['cli']
}).on('script', function (err, args) {
    !err && console.info(args.execution.environment.values.toJSON());
}).on('test'/* or, prerequest */, function (err, args) {
    !err && console.info(args.executions[0].result.environment.values.toJSON());
});
3 Likes