INTRODUCTION
This article outlines automation of APIs using postman and
new line command line interface as well as batch setup. The paper proposes a
way to create collections in postman, use those collection in new man for
automation testing and reporting the automation results in different formats.
Overview
Scope of testing will be API testing for this whitepaper.
Postman-Newman CLI provides a command line interface for API automation to run
quick API automation test
Use of Postman
• Testing rest services using POSTMAN
·
Workspace: stores all collections
·
Collections: collections of requests
·
Test suits : contains tests or test cases
• HTTP request Methods
·
Create a record- POST
·
Retrieve/verify data – GET
·
Update data – PUT
·
Delete data – DELETE
• URL : domain + URI (also call as endpoints)
API Architecture
API calls Collection include mainly three things:
• HTTP headers
• HTTP Request (POST, GET, PUT, DELETE )
• Status Code/ Response Code
·
Date
·
Version
·
Description
·
Author
Newman
Newman is a command line Collection Runner for Postman. It
allows you to run and test a Postman Collection directly from the command line.
It is built with extensibility in mind so that you can easily integrate it with
your continuous integration servers and build systems.
Newman maintains feature parity with Postman and allows you
to run collections the way they are executed inside the collection runner in
Postman.
Newman resides in the NPM registry and on GitHub.
Pre-requisites
➢ Installation can be done in
two ways o Install as google plug in
·
Download as application
o
Download and install node js using below link
Link: https://nodejs.org/en/download/
o
Install newman cli globally: npm install -g
newman
o To check the version of npm : Npm -v
o To check the version of newman : Newman -v
➢ To get HTML reports in postman
,downloa using the cmd : install -g newman-reporter-htmlextra
Usage
➢ After installing, you can
create request collections in postman and run the collection through postman
To share the collections through postman with other test
members use below Share collection option.
To export the
collection use the Export button. Once you export the collection, use this
collection to run through newman
API Automation
Framework in Postman-Newman CLI
API automation framework can we implement using following
way.
A.
Define phase
·
In define phase- we need to create different
test collection based on the test
·
requirement and set of data and environments
B.
Execute Phase
·
Once the collections are defined we need to
export them and get check in the repositories using github or bitbucket
·
Write the batch job using command line interface
for Newman commands to run the collection and generate the report formats
C.
Automate phase
·
In Jenkin, we need to create new item with
freestyle project
·
Add build step with “Execute Shell” shell
command
·
Assign the newman command or batch job in Jenkin
project to get the continuous
·
integration
·
Click save
Run from command line with environment specific
collection
➢ Basic setup
--folder [folderName] Specify a single folder to run from a
collection.
-e, --environment [file|URL] Specify a Postman environment
as a JSON [file] -d, --iteration-data [file] Specify a data file to use either
json or csv
-g, --globals [file] Specify a Postman global file as JSON
[file]
-n, --iteration-count [number] Define the number of
iterations to run
➢ Request options
--delay-request [number] Specify a delay (in ms) between
requests [number] --timeout-request [number] Specify a request timeout (in ms)
for a request
➢ Misc.
--bail Stops the runner when a test case fails
--silent Disable terminal output
--color off Disable colored output (auto
-k, --insecure Disable strict ssl
-x, --suppress-exit-code Continue running tests even after a
failure, but exit with code=0 --ignore-redirectsDisable automatic following of
3XX responses
--verbose Show detailed information of collection run and
each request sent
Use the -n option to set the number of iterations to run the
collection. Steps to run the collection
o Go to command line with folder in which you kept the
postman collection To run the test collection through Newman command line
➢
You can run collection on specific environment with below command newman run
[collection_filename.son] -e [environment_filename. json]
➢ Path of newman in system :
C:\Users\[User Name]\newman
Save Results
Results can be saved as JSON data, HTML report, excel
report, command line report, junit report and multiple format together as well.
By passing a filepath to command you indicate where the file should be
generated. If no filename is passed, a default will be used.
c:\Users\[user dir]\Desktop\Postman Files>newman run
"example collection1.postman_collection.json" - d data.csv -r
htmlextra
-e is the flag for
Environment. This should run through your entire Collection of end.
html report
Newman run “collection name.json” -e “environment.json” -r
htmlextra
Junit report
Newman run “collection name.json” -e “environment.json” -r
junit
excel report
Newman run “collection name.json” -e “environment.json” -r
csv
Command line report
Newman run “collection name.json” -e “environment.json” -r
cli
json report
Newman run “collection name.json” -e “environment.json” -r
json
Multiple format report
Newman run “collection name.json” -e “environment.json” -r
csv,htmlextra,junit
To export report to any location
Newman run “collection name.json” -e “environment.json” -r
json -export “newpath” Result: