We’re currently using postman to test our endpoints. We have multiple collections and environments. Our API uses a JWT token for security.
We’d like to run our collections and report on the results outside of the postman UI.
I’m currently using (or trying to) a newman library script (and running it via nodejs) such that it triggers the collection and spits out an htmlextra report.
I’m having a very difficult time getting this to work correctly as the newman library doesn’t have access to the variables in postman and we have to export the enviornment json file, but we don’t keep our API key in the “initial value” of the environment variables. This means I have to copy\paste the jwt token into the environment json.
The script is turning into a mix of getpostman api calls and an exported json file with the jwt token copy and pasted into it.
So not maintainable or easy by any means.
What is the easiest way to accomplish what we’re trying to do?
-Thanks
BTW, here’s an example of the script.
require('dotenv').config();
const { Console } = require('console');
const newman = require('newman'); // require newman in your project
const key = process.env.postman_api_key;
// The signature for the run function is newman.run(options: object , callback: function) => run:
EventEmitter
newman.run(
{
//collection: require('.\\Orders_1.postman_collection.json'),
collection: 'https://api.getpostman.com/collections/13204628-74a6e824-c8d1-45fd-83e8-8a9003304b37?apikey=' + key,
environment: require('.\\localHost.postman_environment.json'),
//environment: 'https://api.getpostman.com/environments/12415606-e03e06c1-00f4-422a-891a-4e6984aa7cf3?apikey=' + key,
reporters: 'htmlextra', // htmlextra is a reporting package for newman that will require installlation using NPM.
reporter:
{ //Go here for documentation: https://www.npmjs.com/package/newman-reporter-htmlextra
htmlextra: //Report options
{
export: '.\\Results.html', //Directory and name
template: '.\\InnovaAPITemplate.hbs', //Template used for report. Html, CSS and JS are all embedded.
title: 'Innovations API',
showEnviornmentData: true,
browserTitle: "Innovations API",
showMarkdownLinks: true,
showFolderDescription: true,
//skipSensitiveData: true //Hides request header because it can contain the authorization tokens.
}
}
},// <-- End of options object
function (err,summary)// <-- Beginning of callback function
{
if (err)
{
console.log(err);
throw err;
} else
{
//console.log(summary);
}
}// <-- End of callback
).on('start', function (err, args) { // <-- start event.
console.log('running a collection...');
}).on('done', function (err, summary) { // <-- done event.
if (err || summary.error) {
console.error('\nCollection run encountered an error.');
}
else {
console.log('\nCollection run completed.');
}
})
;