Newman – Command line integration with Postman

To run the test from command line window, Postman has newly npm Package (Newman).

Here quick steps to start with newman:

  1. Install latest version of Node (Node.js) in the computer. Download the Windows installer from the js® web site.
  2. To see if NPM is installed, type npm -v in command prompt.
  3. 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
  4. Set the path of Node Bin Folder (ex: C:\Program Files\nodejs\node_modules\npm\bin) in the Computer path Variable.
  5. Open the cmd and type following command “npm install -g newman”.
  6. It will install Newman in the PC.
  7. Postman provides a feature to download the collection as JSON Data.
  8. Download the collection from the Postman
  9. Open the command window in the downloaded path of collection and type following Command “newman run GetBalanceService.json -r html”
  10. Observe the Command window in the Postman
  11. Observe the Reports.html in the same Directory
  12. 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”
  13. If want to run any specific folder only use same command like:
    “newman run GetBalanceService.json –folder DemoFolder -e dev_environment.json -r html”
  14. 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:

-r html,cli,json,junit

Not like:   -r html, cli , json,junit

Junit will generate xml reports like:

 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.

–folder <name>
Run requests within a particular folder in a collection.

–export-environment <path>
The path to the file where Newman will output the final environment variables file before completing a run.

–export-globals <path>
The path to the file where Newman will output the final global variables file before completing a run.

–export-collection <path>
The path to the file where Newman will output the final collection file before completing a run.

–timeout <ms>
Specify the time (in milliseconds) to wait for the entire collection run to complete execution.

–timeout-request <ms>
Specify the time (in milliseconds) to wait for requests to return a response.

–timeout-script <ms>
Specify the time (in milliseconds) to wait for scripts to complete execution.

-k, –insecure
Disables SSL verification checks and allows self-signed SSL certificates.

–ignore-redirects
Prevents newman from automatically following 3XX redirect responses.

–delay-request
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.

-x, –suppress-exit-code
Specify whether or not to override the default exit code for the current run.

–color
Use this option to force colored CLI output (for use in CLI for CI / non TTY environments).

–no-color
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.

–disable-unicode
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.

–global-var “<global-variable-name>=<global-variable-value>”
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”.

Leave a Reply

Your email address will not be published. Required fields are marked *