API Testing with Postman and Newman.
Note: You might find some items that are not optimized. Feel free to create a PR if you want to make some optimization.
-
Running API Test using
node js
. You can use your own Imported Collection and Environment. These are controlled inside the./conf/conf.js
file. -
Put your postman Collection in
./conf/collection/
and make sure the file name format is<whatever file name you have>_collection.json
-
Put your Environment in
./conf/environment/
and make sure the file name format is<environment>.<whatever name>_environment.json
For more info, please visit Newman API Reference
newman.run({
collection: require(String(config.Collection)),
environment: require(String(config.Environment)),
timeoutRequest: 60000,
timeoutScript: 60000,
delayRequest: 500,
reporters: ['cli', 'htmlextra', 'junit'],
reporter: {
htmlextra: {
export: './report/' + config.ReportName + '_' + config.Label + '.html',
title: config.ReportName + ' ' + config.Label,
darkTheme: true,
skipSensitiveData: false,
},
junit: {
export: './report/' + config.ReportName + '_' + config.Label + '.xml',
},
},
}).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.');
}
});
-
Clone the repo —
https://github.com/ianoroceo/Postman-Newman.git
-
Install Postman -
https://www.postman.com/downloads/
-
Import Collection and Environment
-
Running Tests using Postman Collection Runs
-
(Optional)Install nvm in your machine
-
Install nodeJs using nvm. You can also install nodeJS without using nvm. Here are some references if you are installing not using nvm
-
Install your favorite IDE. I used VS Code for this
-
On your terminal (mac) / cmd (windows), go to your project directory and install the Node Packages using
npm install
-
Run your test.
npm run test:dev
. To run on other environments, please provide the environment argument- Note: before running your test, if you made changes please execute ESLint first
npm run lint-fix
-
Once all tests are executed, an aggregated report will be generated under
./report
. -
Test Results can be also posted on Slack. Please read documentation how to setup Slack Notification