Newman
Newman
Newman is a CLI tool for running Postman collections.
Setup
You need NodeJS (which includes the npm package manager) or NVM (Node Version Manager).
1
npm install -g newman
Check it was properly installed
1
newman -v
Run it
You may check it works properly by exporting a Postman Collection as a json file from the Postman App.
1
newman run examples/sample-collection.json
You may also run a remote json file.
1
newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv
Hints
HTML Reporters
Basic reporter
1
2npm install -g newman-reporter-html
newman run examples/demo-collection.json -r htmlExtended reporter
1
2npm install -g newman-reporter-htmlextra
newman run examples/demo-collection.json -r htmlextra
Pre-request scripts
Pre-processing
- setting variable values
- parameters
- headers
- body data
- pre-request scripts for debugging code (e.g. logging output)
1
pm.collectionVariables.set('methodName', 'myMethodName')
Learn with example:
Calculate hashed version of
${developerId}${methodName}${FORMAT}${authKey}${timeStamp}
Python solution (and manually paste on postman)
1
2from hashlib import md5
md5(string_to_hash)Postman solution
pre-request script tab on request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15const moment = require("moment");
const timeStamp = moment.utc.().format('YYYYMMDDHHmmss');
const devId = pm.environmentVariables.get('devId');
const authKey = pm.environmentVariables.get('authKey');
const methodName = pm.environmentVariables.get('methodName');
// use cryptoJS
const signature = CryptoJS.MD5(`${devId}${methodName}${authKey}${timeStamp}`).toString();
// set the new environment variable
postman.setEnvironmentVariable('signature', signature);
postman.setEnvironmentVariable('timeStamp', timeStamp);On call
Integrations
Newman on Jenkins
Obtain graphical reports
Create job/project “Postman collection”
Go to configure/build
You may set the value of execute batch command:
1
2
3# there should be no spaces on the reporters arguments
newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv \
--reporters cli,junit --reporter-junit-export “newman/myreport.xml”When the project is built, you may go to Workspace/newman and check the xml report.
Publish the report
- Go to Configure
- Go to post-build actions
- Select publish Junit test result report
- Enter the path of the file in Test Report XMLs and save the changes
- Click on Build Now to build the project again
- In the Build history section, click on the date and time to open up the build results
- Click on Test Result
Create trends
- Build the project a couple of times to set a general trend as sometimes Jenkins does not show the report with one build.
- Refresh the page.
- You will see the generalized report on the dashboard as Test Result Trend.