Export Collection: Way 1
Now click on the […] button besides your collection
Click on Share collection
Click on “Get public link” button
Then you will get a link. This link you can share with anybody and h/she can import the collection
Export Collection: Way 2
Click on the […] button besides your collection
Click on Export button and save to your local disk.
Now anybody can import the collection
Export Environment
Same way, you can export the environment and then save to your local disk where you saved the collection.
Import Collection
Go to collection tab.
Click on Import button
Switch to Link tab and paste the link you just generated.
Click on Continue button and then Import
You will see the whole collection has been imported. Any body can import your collection this way.
Import Environment
Go to Environment tab
Click on Import button
Locate the environment file you just exported.
Now the importer can call any API
Run Collection
Select your collection and you will see a tab named Run. Click on there.
You will see Iteration is set by default 1 which means the whole test will run for 1 time.
Click on “Run Customer API Testing” button
Run collection using Newman
Create a folder named Customer_API_Testing
Open the blank folder with VS code
Open the command prompt and hit the command:
npm init -y
It will generate package.json file
Install newman by giving this command in cmd
npm i newman
you will see that newman has been installed and showing the package name at package.json file under dependencies tag
Now create a folder named collection
Now, export collection and environment from postman. Save it to the “collection” folder you just created
Make sure, when saving the collection and environment files, there should not contain any space within the file name. You can fillup the space (if any) with underscore_
For example, postman collection file name is, customer_api_collection.json and environment file name is customer_api_env.json
Now give this command:
npx newman run .\collection\customer_api_collection.json -e .\collection\customer_api_env.json -n 1
This command means, newman will run your collection using the environment file for 1 time.
Output:
HTML report generate using Newman
Install following package by this command:
npm i newman-reporter-htmlextra
Now create another file named report.js
copy paste following code:
const newman = require('newman');
newman.run({
collection: require('./collection/customer_api_collection.json'), // pointing to local JSON file.
environment: require('./collection/customer_api_env.json'), // pointing to local env file
iterationCount: 1,
reporters: 'htmlextra',
reporter: {
htmlextra: {
export: './Reports/report.html', // If not specified, the file will be written to `newman/` in the current working directory.
}
}
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!');
});
Now create a folder named Reports. If you do not create this folder, the report will be generate to a new folder named ‘newman’ in current working directory.
Then go to the package file and update “test” value under scripts as:
“node report.js”
Now hit this command:
npm test
You will see a html report named report.html will be generate in Reports folder
Now reveal the folder and open the html file
You will see the result in a html report
Get API collection from here:
https://www.getpostman.com/collections/a3c58035e0557105b855
Here is the full project:
https://github.com/salmansrabon/newman-htmlreporter-postman-collection-automation
Leave a Reply