To run the test from command line window, Postman has newly npm Package (Newman).
Here quick steps to start with newman:
- Install latest version of Node (Node.js) in the computer. Download the Windows installer from the js® web site.
- To see if NPM is installed, type npm -v in command prompt.
- In case npm is already installed and want to update (To run Newman, ensure that you have NodeJS >= v4) run following command from cmd: npm install -g npm-windows-upgrade
- Set the path of Node Bin Folder (ex: C:\Program Files\nodejs\node_modules\npm\bin) in the Computer path Variable.
- Open the cmd and type following command “npm install -g newman”.
- It will install Newman in the PC.
- Postman provides a feature to download the collection as JSON Data.
- Download the collection from the Postman
- Open the command window in the downloaded path of collection and type following Command “newman run GetBalanceService.json -r html”
- Observe the Command window in the Postman
- Observe the Reports.html in the same Directory
- If using the environment, export the environment json file and use in the command. Like:
“newman run GetBalanceService.json –e dev_environment.json -r html”
- If want to run any specific folder only use same command like:
“newman run GetBalanceService.json –folder DemoFolder -e dev_environment.json -r html”
- Newman supports different reporting formats like json, junit etc. To view the output JSON data of API, modify the command as “newman run GetBalanceService.json –folder DemoFolder -e dev_environment.json -r html,json,junit”
Note: Spaces should not be used between reporter names / commas whilst specifying a comma separted list of reporters. For instance:
Not like: -r html, cli , json,junit
Junit will generate xml reports like:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Sample Postman Collection">
<testsuite name="A simple GET request" id="17d87a3b-fdc8-4b18-9815-950a42d87f59" time="1965">
<testcase name="response code is 200"/>
<testsuite name="A simple POST request" id="45805ccf-86f6-44d1-b1fa-18431f4025e5" time="273"/>
<testsuite name="A simple POST request with JSON body" id="0d5736de-0cf1-46a9-b057-3997c275af4b" time="309"/>
Creating and using custom reporters
Newman also supports custom reporters, provided that the reporter works with Newman’s event sequence. Working examples on how Newman reporters work can be found in lib/reporters. For instance, to use the Newman teamcity reporter.
Newman command line options
newman run <collection-file-source> [options]
-e <source>, –environment <source>
Specify an environment file path or URL. Environments provide a set of variables that one can use within collections.
-g <source>, –globals <source>
Specify file path or URL for global variables. Global variables are similar to environment variables but has a lower precedence and can be overridden by environment variables having same name.
-d <source>, –iteration-data <source>
Specify a data source file (CSV) to be used for iteration as a path to a file or as a URL.
-n <number>, –iteration-count <number>
Specifies the number of times the collection has to be run when used in conjunction with iteration data file.
Run requests within a particular folder in a collection.
The path to the file where Newman will output the final environment variables file before completing a run.
The path to the file where Newman will output the final global variables file before completing a run.
The path to the file where Newman will output the final collection file before completing a run.
Specify the time (in milliseconds) to wait for the entire collection run to complete execution.
Specify the time (in milliseconds) to wait for requests to return a response.
Specify the time (in milliseconds) to wait for scripts to complete execution.
Disables SSL verification checks and allows self-signed SSL certificates.
Prevents newman from automatically following 3XX redirect responses.
Specify the extent of delay between requests (milliseconds).
–bail [optional modifiers]
Specify whether or not to stop a collection run on encountering the first error.
Can optionally accept modifiers, currently include folder and failure.
folder allows you to skip the entire collection run in case an invalid folder was specified using the –folder option or an error was encountered in general.
failure would gracefully stop a collection run on the first test failure.
Specify whether or not to override the default exit code for the current run.
Use this option to force colored CLI output (for use in CLI for CI / non TTY environments).
Newman attempts to automatically turn off color output to terminals when it detects the lack of color support. With this property, one can forcibly turn off the usage of color in terminal output for reporters and other parts of Newman that output to console.
Specify whether or not to force the unicode disable option. When supplied, all symbols in the output will be replaced by their plain text equivalents.
Allows the specification of global variables via the command line, in a key=value format. Multiple CLI global variables can be added by using –global-var multiple times, like so: –global-var “foo=bar” –global-var “alpha=beta”.