API Testing With Newman Node.js in VS CODE with commands
newman is used for generating test report
==== After opening file in VS code for generating package.json ===== Terminal: "nmp init -y"
==== installing newman ==== "npm i newman"
==== exporting collection from postman ====
- Go to desired collection
- Check initial values are ok if not click Persist All and Save
- Create a folder in VS Code named collection
- Then Export from postman in that folder
====for running the collection and display newman console report =====
npx newman run .\collection\collection.json //exported file name
==== for html report =====
- install htmlextra npm i newman-reporter-htmlextra
- package will be included under dependencies in package.json file
=== report.js file =======
const newman = require('newman') newman.run({ collection:require('./collection/collection.json'),
reporters: 'htmlextra',
iterationCount: 1,
reporter: {
htmlextra:{
export:'./Reports/report.html', //if not specified,the file will be written to newman/
} }
}, function(err){ if (err) {throw err;} console.log('collection run complete'); }
);
- create report folder where reports will be saved 2.export:'./Reports(root folder)/report.html' -- it specifies where reports will be saved
- === run report === node .\report.js
- Report will be generated in html file
or
Go to package.json file
- inside test script write "node report.js"
- npm test
==== Running collection with api ====
- npx newman run