My question:
I have a collection that I’m trying to automate as part of launching my company’s API service. Currently the collection works in Postman, but I’m trying to add the automation portion of running it with Newman.
I have a javascript module build that runs the process from what I’ve read in the documentation:
const main = async () => {
const regionName = process.env['REGION_NAME'];
const environment = process.env['ENVIRONMENT'];
const mfaToken = process.env['MFA_TOKEN'];
const accessToken = process.env['ACCESS_TOKEN'];
const userEmail = process.env['USER_EMAIL'];
const userPassword = process.env['USER_PASSWORD'];
const config = await buildConfig(regionName, environment);
const newmanConfig = {
collection,
environment: {
id: "bd5fbe4a-a5af-4536-9e94-7c66a14ec6a5",
name: config.apiEnvironment,
values: [
{
key: 'itglue',
value: config.baseUrl,
enabled: true
},
{
key: "itglue-api",
value: config.apiUrl,
enabled: true
},
{
key: 'refresh_subdomain',
value: config.subdomain,
enabled: true
},
{
key: 'jwt_subdomain',
value: config.subdomain,
enabled: true
},
{
key: 'api-token',
value: accessToken,
enabled: true
},
{
key: 'mfa_token',
value: mfaToken,
enabled: true
},
{
key: 'user_email',
value: userEmail,
enabled: true
},
{
key: 'user_password',
value: userPassword,
enabled: true
}
],
_postman_variable_scope: "environment",
_postman_exported_at: "2022-08-18T14:38:14.591Z",
_postman_exported_using: "Postman/9.28.2"
},
reporters: ['cli', 'junit'],
reporter: {
junit: {
export: join(
process.cwd(),
'./resources/reports/it-glue-newman-report.xml'
)
}
}
}
newman.run(newmanConfig)
.on('start', (err, args) => {
if (err) throw err;
console.log('======== Run Api Tests... ========')
})
.on('done', (err, summary) => {
if (err) {
throw err;
} else if (summary.error) {
throw summary.error;
} else {
console.log(summary.run);
}
});
};
However, in testing, I can’t get the start
event to emit. The application completes without executing any of the Newman tests for the API.
I’m kind of stumped as to what is going wrong at this point. Anyone have any thoughts?
How I found the problem:
Trying to run Newman with my configuration.
I’ve already tried:
- Writing the script as solely CommonJS instead of a ESM Module
- Changing Newman’s import to use CommonJS instead of ESM import
- Using a callback function instead of the EventEmitter events
- Using Newman from the commandline (this works)