Manage all of your organization's APIs in Postman, with the industry's most complete API development environment.
newman the cli companion for postman
Newman is a command-line collection runner for Postman. It allows you to effortlessly 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.
Table of contents
- Getting Started
- Usage
- Command Line Options
- API Reference
- Reporters
- External Reporters
- File Uploads
- Using Newman with the Postman API
- Using Newman in Docker
- Using Socks Proxy
- Migration Guide
- Compatibility
- Contributing
- Community Support
- License
Getting started
To run Newman, ensure that you have Node.js >= v16. Install Node.js via package manager.
Installation
The easiest way to install Newman is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.
$ npm install -g newman
This installs Newman globally on your system allowing you to run it from anywhere. If you want to install it locally, Just remove the -g
flag.
Using Homebrew
Install Newman globally on your system using Homebrew.
$ brew install newman
Usage
Using Newman CLI
The newman run
command allows you to specify a collection to be run. You can easily export your Postman
Collection as a json file from the Postman App and run it using Newman.
$ newman run examples/sample-collection.json
If your collection file is available as an URL (such as from our Cloud API service), Newman can fetch your file and run it as well.
$ newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv
For the complete list of options, refer the Command Line Options section below.
Using Newman as a Library
Newman can be easily used within your JavaScript projects as a Node.js module. The entire set of Newman CLI functionality is available for programmatic use as well. The following example runs a collection by reading a JSON collection file stored on disk.
const newman = require('newman'); // require newman in your project
// call newman.run to pass `options` object and wait for callback
newman.run({
collection: require('./sample-collection.json'),
reporters: 'cli'
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!');
});
For the complete list of options, refer the API Reference section below.
Using Reporters with Newman
Reporters provide information about the current collection run in a format that is easy to both: disseminate and assimilate.
Reporters can be configured using the -r
or --reporters
options. Inbuilt reporters in newman are: cli
, json
, junit
, progress
and emojitrain
.
CLI reporter is enabled by default when Newman is used as a CLI, you do not need to specifically provide the same as part of reporters option. However, enabling one or more of the other reporters will result in no CLI output. Explicitly enable the CLI option in such a scenario. Check the example given below using the CLI and JSON reporters:
$ newman run examples/sample-collection.json -r cli,json
For more details on Reporters and writing your own External Reporters refer to their corresponding sections below.
Command Line Options
newman [options]
-
-h
,--help
Show command line help, including a list of options, and sample use cases. -
-v
,--version
Displays the current Newman version, taken from package.json
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. Read More -
-g <source>
,--globals <source>
Specify the file path or URL for global variables. Global variables are similar to environment variables but have a lower precedence and can be overridden by environment variables having the same name. -
-d <source>
,--iteration-data <source>
Specify a data source file (JSON or CSV) to be used for iteration as a path to a file or as a URL. Read More -
-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/folders or specific requests in a collection. Multiple folders or requests can be specified by using --folder multiple times, like so: --folder f1 --folder f2 --folder r1 --folder r2. -
--working-dir <path>
Set the path of the working directory to use while reading files with relative paths. Default to current directory. -
--no-insecure-file-read
Prevents reading of files situated outside of the working directory. -
--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). -
--cookie-jar <path>
Specify the file path for a JSON Cookie Jar. Usestough-cookie
to deserialize the file. -
--export-cookie-jar <path>
The path to the file where Newman will output the final cookie jar file before completing a run. Usestough-cookie
's serialize method. -
--bail [optional modifiers]
Specify whether or not to stop a collection run on encountering the first test script error.
Can optionally accept modifiers, currently includefolder
andfailure
.
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.
On the failure of a test,failure
would gracefully stop a collection run after completing the current test script. -
-x
,--suppress-exit-code
Specify whether or not to override the default exit code for the current run. -
--color <value>
Enable or Disable colored CLI output. The color value can be any of the three:on
,off
orauto
(default).
Withauto
, Newman attempts to automatically turn color on or off based on the color support in the terminal. This behaviour can be modified by using theon
oroff
value accordingly. -
--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"
. -
--env-var "<environment-variable-name>=<environment-variable-value>"
Allows the specification of environment variables via the command line, in a key=value format. Multiple CLI environment variables can be added by using--env-var
multiple times, like so:--env-var "foo=bar" --env-var "alpha=beta"
. -
--verbose
Show detailed information of collection run and each request sent.
SSL
Client Certificates
Client certificates are an alternative to traditional authentication mechanisms. These allow their users to make authenticated requests to a server, using a public certificate, and an optional private key that verifies certificate ownership. In some cases, the private key may also be protected by a secret passphrase, providing an additional layer of authentication security.
Newman supports SSL client certificates, via the following CLI options:
Using a single SSL client certificate
-
--ssl-client-cert
The path to the public client certificate file. -
--ssl-client-key
The path to the private client key (optional). -
--ssl-client-passphrase
The secret passphrase used to protect the private client key (optional).
Using SSL client certificates configuration file (supports multiple certificates per run)
--ssl-client-cert-list
The path to the SSL client certificate list configuration file (JSON format). See examples/ssl-client-cert-list.json.
This option allows setting different SSL client certificate according to URL or hostname.
This option takes precedence over --ssl-client-cert
, --ssl-client-key
and --ssl-client-passphrase
options. If there is no match for the URL in the list, these options are used as fallback.
Trusted CA
When it is not wanted to use the --insecure
option, additionally trusted CA certificates can be provided like this:
--ssl-extra-ca-certs
The path to the file, that holds one or more trusted CA certificates in PEM format
Configuring Proxy
Newman can also be configured to work with proxy settings via the following environment variables:
HTTP_PROXY
/http_proxy
HTTPS_PROXY
/https_proxy
NO_PROXY
/no_proxy
For more details on using these variables, refer here.
API Reference
newman.run(options: object , callback: function) => run: EventEmitter
The run
function executes a collection and returns the run result to a callback function provided as parameter. The
return of the newman.run
function is a run instance, which emits run events that can be listened to.
Parameter | Description |
---|---|
options | This is a required argument and it contains all information pertaining to running a collection. Required Type: object |
options.collection | The collection is a required property of the options argument. It accepts an object representation of a Postman Collection which should resemble the schema mentioned at https://schema.getpostman.com/. The value of this property could also be an instance of Collection Object from the Postman Collection SDK.As string , one can provide a URL where the Collection JSON can be found (e.g. Postman Cloud API service) or path to a local JSON file.Required Type: object|string PostmanCollection |
options.environment | One can optionally pass an environment file path or URL as string to this property and that will be used to read Postman Environment Variables from. This property also accepts environment variables as an object . Environment files exported from Postman App can be directly used here.Optional Type: object|string |
options.envVar | One can optionally pass environment variables as an array of key-value string object pairs. It will be used to read Postman Environment Variables as well as overwrite environment variables from options.environments . Optional Type: array|object |
options.globals | Postman Global Variables can be optionally passed on to a collection run in form of path to a file or URL. It also accepts variables as an object .Optional Type: object|string |
options.globalVar | One can optionally pass global environment variables as an array of key-value string object pairs. It will be used to read Postman Global Environment Variables as well as overwrite global environment variables from options.globals . Optional Type: array|object |
options.iterationCount | Specify the number of iterations to run on the collection. This is usually accompanied by providing a data file reference as options.iterationData .Optional Type: number , Default value: 1 |
options.iterationData | Path to the JSON or CSV file or URL to be used as data source when running multiple iterations on a collection. Optional Type: string |
options.folder | The name or ID of the folder/folders (ItemGroup) in the collection which would be run instead of the entire collection. Optional Type: string|array |
options.workingDir | The path of the directory to be used as working directory. Optional Type: string , Default value: Current Directory |
options.insecureFileRead | Allow reading files outside of working directory. Optional Type: boolean , Default value: true |
options.timeout | Specify the time (in milliseconds) to wait for the entire collection run to complete execution. Optional Type: number , Default value: Infinity |
options.timeoutRequest | Specify the time (in milliseconds) to wait for requests to return a response. Optional Type: number , Default value: Infinity |
options.timeoutScript | Specify the time (in milliseconds) to wait for scripts to return a response. Optional Type: number , Default value: Infinity |
options.delayRequest | Specify the time (in milliseconds) to wait for between subsequent requests. Optional<br |