With Newman and Async, you can do simultaneous request calls which will be very helpful for performance tests.
Here are what you'll need to do to get it working:
- Install Newman by following the instructions on http://blog.getpostman.com/2015/04/09/installing-newman-on-windows/
In my case, I didn’t have to install Python to get it working. - Create/use a folder for the tests
- Export a Postman collection into a file
- Export a Postman environment that you want to invoke the calls to
- Open a command prompt in administrator mode on the folder from step 2
- Install async module by typing npm install --save async
- Create a .js file
- Run the .js file from step 7 from command prompt node fileName.js
var path = require('path'),
async = require('async'), //https://www.npmjs.com/package/async
newman = require('newman'),
parametersForTestRun = {
collection: path.join(__dirname, 'postman_collection.json'), // your collection
environment: path.join(__dirname, 'postman_environment.json'), //your env
};
parallelCollectionRun = function(done) {
newman.run(parametersForTestRun, done);
};
// Runs the Postman sample collection thrice, in parallel.
async.parallel([
parallelCollectionRun,
parallelCollectionRun,
parallelCollectionRun
],
function(err, results) {
err && console.error(err);
results.forEach(function(result) {
var failures = result.run.failures;
console.info(failures.length ? JSON.stringify(failures.failures, null, 2) :
`${result.collection.name} ran successfully.`);
});
});
What would I add to parametersForTest if my collection needs to call an external JSON file? what would I add if I want multiple iterations? These are specified in the newman documentation as -d and -n.
ReplyDelete