1 | ### Newman v4 has been released. Check the [migration guide](MIGRATION.md#migrating-from-v3-to-v4) and [changelog](https://github.com/postmanlabs/newman/blob/v4.0.0/CHANGELOG.yaml#L3) for more details.
|
2 |
|
3 | <a href="https://www.getpostman.com/"><img src="https://raw.githubusercontent.com/postmanlabs/postmanlabs.github.io/develop/global-artefacts/postman-logo%2Btext-320x132.png" /></a><br />
|
4 | _Supercharge your API workflow<br/>Modern software is built on APIs. Postman helps you develop APIs faster._
|
5 |
|
6 | # newman <sub>_the cli companion for postman_</sub>
|
7 |
|
8 | 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.
|
9 |
|
10 |
|
11 | ## Table of contents
|
12 |
|
13 | 1. [Getting Started](#getting-started)
|
14 | 2. [Usage](#usage)
|
15 | 1. [Using Newman CLI](#using-newman-cli)
|
16 | 2. [Using Newman as a Library](#using-newman-as-a-library)
|
17 | 3. [Using Reporters with Newman](#using-reporters-with-newman)
|
18 | 3. [Command Line Options](#command-line-options)
|
19 | 1. [newman-options](#newman-options)
|
20 | 2. [newman-run](#newman-run-collection-file-source-options)
|
21 | 3. [SSL Client Certificates](#ssl-client-certificates)
|
22 | 4. [Configuring Proxy](#configuring-proxy)
|
23 | 4. [API Reference](#api-reference)
|
24 | 1. [newman run](#newmanrunoptions-object--callback-function--run-eventemitter)
|
25 | 2. [Run summary object](#newmanruncallbackerror-object--summary-object)
|
26 | 3. [Events emitted during a collection run](#newmanrunevents)
|
27 | 5. [Reporters](#reporters)
|
28 | 1. [Configuring Reporters](#configuring-reporters)
|
29 | 2. [CLI Reporter](#cli-reporter)
|
30 | 3. [JSON Reporter](#json-reporter)
|
31 | 4. [JUnit Reporter](#junitxml-reporter)
|
32 | 5. [HTML Reporter](#html-reporter)
|
33 | 6. [External Reporters](#external-reporters)
|
34 | 1. [Using External Reporters](#using-external-reporters)
|
35 | 2. [Creating Your Own Reporter](#creating-your-own-reporter)
|
36 | 7. [File Uploads](#file-uploads)
|
37 | 8. [Using Newman with the Postman API](#using-newman-with-the-postman-api)
|
38 | 9. [Using Newman in Docker](#using-newman-in-docker)
|
39 | 10. [Migration Guide](#migration-guide)
|
40 | 11. [Compatibility](#compatibility)
|
41 | 12. [Contributing](#contributing)
|
42 | 13. [Community Support](#community-support)
|
43 | 14. [License](#license)
|
44 |
|
45 |
|
46 | ## Getting started
|
47 |
|
48 | To run Newman, ensure that you have Node.js >= v6. [Install Node.js via package manager](https://nodejs.org/en/download/package-manager/).
|
49 |
|
50 | ### Installation
|
51 | 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.
|
52 |
|
53 | ```console
|
54 | $ npm install -g newman
|
55 | ```
|
56 | 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.
|
57 |
|
58 | [back to top](#table-of-contents)
|
59 |
|
60 | ## Usage
|
61 |
|
62 | ### Using Newman CLI
|
63 | The `newman run` command allows you to specify a collection to be run. You can easily export your Postman
|
64 | Collection as a json file from the [Postman App](https://www.getpostman.com/apps) and run it using Newman.
|
65 |
|
66 | ```console
|
67 | $ newman run examples/sample-collection.json
|
68 | ```
|
69 |
|
70 | If your collection file is available as an URL (such as from our [Cloud API service](https://api.getpostman.com)),
|
71 | Newman can fetch your file and run it as well.
|
72 |
|
73 | ```console
|
74 | $ newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv
|
75 | ```
|
76 |
|
77 | For the complete list of options, refer the [Command Line Options](#command-line-options) section below.
|
78 |
|
79 | ![terminal-demo](https://raw.githubusercontent.com/postmanlabs/postmanlabs.github.io/develop/global-artefacts/newman-terminal.gif)
|
80 |
|
81 | ### Using Newman as a Library
|
82 | 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.
|
83 |
|
84 | ```javascript
|
85 | const newman = require('newman'); // require newman in your project
|
86 |
|
87 | // call newman.run to pass `options` object and wait for callback
|
88 | newman.run({
|
89 | collection: require('./sample-collection.json'),
|
90 | reporters: 'cli'
|
91 | }, function (err) {
|
92 | if (err) { throw err; }
|
93 | console.log('collection run complete!');
|
94 | });
|
95 | ```
|
96 |
|
97 | For the complete list of options, refer the [API Reference](#api-reference) section below.
|
98 |
|
99 | ### Using Reporters with Newman
|
100 | Reporters provide information about the current collection run in a format that is easy to both: disseminate and assimilate.
|
101 | Reporters can be configured using the `-r` or `--reporters` options. Inbuilt reporters in newman are: `cli`, `json`, `junit`, `progress` and `emojitrain`.
|
102 |
|
103 | 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:
|
104 |
|
105 | ```console
|
106 | $ newman run examples/sample-collection.json -r cli,json
|
107 | ```
|
108 |
|
109 | For more details on [Reporters](#reporters) and writing your own [External Reporters](#external-reporters) refer to their corresponding sections below.
|
110 |
|
111 | [back to top](#table-of-contents)
|
112 |
|
113 | ## Command Line Options
|
114 |
|
115 | ### `newman [options]`
|
116 |
|
117 | - `-h`, `--help`<br />
|
118 | Show command line help, including a list of options, and sample use cases.
|
119 |
|
120 | - `-v`, `--version`<br />
|
121 | Displays the current Newman version, taken from [package.json](https://github.com/postmanlabs/newman/blob/master/package.json)
|
122 |
|
123 |
|
124 | ### `newman run <collection-file-source> [options]`
|
125 |
|
126 | - `-e <source>`, `--environment <source>`<br />
|
127 | Specify an environment file path or URL. Environments provide a set of variables that one can use within collections.
|
128 | [Read More](https://www.getpostman.com/docs/environments)
|
129 |
|
130 | - `-g <source>`, `--globals <source>`<br />
|
131 | Specify the file path or URL for global variables. Global variables are similar to environment variables but have a lower
|
132 | precedence and can be overridden by environment variables having the same name.
|
133 |
|
134 | - `-d <source>`, `--iteration-data <source>`<br />
|
135 | Specify a data source file (CSV) to be used for iteration as a path to a file or as a URL.
|
136 | [Read More](https://www.getpostman.com/docs/multiple_instances)
|
137 |
|
138 | - `-n <number>`, `--iteration-count <number>`<br />
|
139 | Specifies the number of times the collection has to be run when used in conjunction with iteration data file.
|
140 |
|
141 | - `--folder <name>`<br />
|
142 | Run requests within a particular folder/folders in a collection. Multiple folders can be specified by using
|
143 | `--folder` multiple times, like so: `--folder f1 --folder f2`.
|
144 |
|
145 | - `--export-environment <path>`<br />
|
146 | The path to the file where Newman will output the final environment variables file before completing a run.
|
147 |
|
148 | - `--export-globals <path>`<br />
|
149 | The path to the file where Newman will output the final global variables file before completing a run.
|
150 |
|
151 | - `--export-collection <path>`<br />
|
152 | The path to the file where Newman will output the final collection file before completing a run.
|
153 |
|
154 | - `--timeout <ms>`<br />
|
155 | Specify the time (in milliseconds) to wait for the entire collection run to complete execution.
|
156 |
|
157 | - `--timeout-request <ms>`<br />
|
158 | Specify the time (in milliseconds) to wait for requests to return a response.
|
159 |
|
160 | - `--timeout-script <ms>`<br />
|
161 | Specify the time (in milliseconds) to wait for scripts to complete execution.
|
162 |
|
163 | - `-k`, `--insecure`<br />
|
164 | Disables SSL verification checks and allows self-signed SSL certificates.
|
165 |
|
166 | - `--ignore-redirects`<br />
|
167 | Prevents newman from automatically following 3XX redirect responses.
|
168 |
|
169 | - `--delay-request`<br />
|
170 | Specify the extent of delay between requests (milliseconds).
|
171 |
|
172 | - `--bail [optional modifiers]`<br />
|
173 | Specify whether or not to stop a collection run on encountering the first test script error.<br />
|
174 | Can optionally accept modifiers, currently include `folder` and `failure`.<br />
|
175 | `folder` allows you to skip the entire collection run in case an invalid folder
|
176 | was specified using the `--folder` option or an error was encountered in general.<br />
|
177 | On the failure of a test, `failure` would gracefully stop a collection run after completing the current test script.
|
178 |
|
179 | - `-x`, `--suppress-exit-code`<br />
|
180 | Specify whether or not to override the default exit code for the current run.
|
181 |
|
182 | - `--color <value>`<br />
|
183 | Enable or Disable colored CLI output. The color value can be any of the three: `on`, `off` or `auto`*(default)*.<br/>
|
184 | With `auto`, Newman attempts to automatically turn color on or off based on the color support in the terminal.
|
185 | This behaviour can be modified by using the `on` or `off` value accordingly.
|
186 |
|
187 | - `--disable-unicode`<br />
|
188 | Specify whether or not to force the unicode disable option. When supplied, all symbols in the output will be replaced
|
189 | by their plain text equivalents.
|
190 |
|
191 | - `--global-var "<global-variable-name>=<global-variable-value>"`<br />
|
192 | Allows the specification of global variables via the command line, in a key=value format. Multiple CLI global variables
|
193 | can be added by using `--global-var` multiple times, like so: `--global-var "foo=bar" --global-var "alpha=beta"`.
|
194 |
|
195 | ### SSL Client Certificates
|
196 |
|
197 | 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.
|
198 |
|
199 | Newman supports SSL client certificates, via the following CLI options (available with Newman `v3` style `run` only):
|
200 |
|
201 | - `--ssl-client-cert`<br/>
|
202 | The path to the public client certificate file.
|
203 |
|
204 | - `--ssl-client-key`<br/>
|
205 | The path to the private client key (optional).
|
206 |
|
207 | - `--ssl-client-passphrase`<br/>
|
208 | The secret passphrase used to protect the private client key (optional).
|
209 |
|
210 | ### Configuring Proxy
|
211 |
|
212 | Newman can also be configured to work with proxy settings via the following environment variables:
|
213 |
|
214 | * `HTTP_PROXY` / `http_proxy`
|
215 | * `HTTPS_PROXY` / `https_proxy`
|
216 | * `NO_PROXY` / `no_proxy`
|
217 |
|
218 | For more details on using these variables, [refer here](https://github.com/postmanlabs/postman-request/blob/master/README.md#controlling-proxy-behaviour-using-environment-variables).
|
219 |
|
220 | [back to top](#table-of-contents)
|
221 |
|
222 | ## API Reference
|
223 |
|
224 | ### newman.run(options: _object_ , callback: _function_) => run: EventEmitter
|
225 | The `run` function executes a collection and returns the run result to a callback function provided as parameter. The
|
226 | return of the `newman.run` function is a run instance, which emits run events that can be listened to.
|
227 |
|
228 | | Parameter | Description |
|
229 | |-----------|---------------|
|
230 | | options | This is a required argument and it contains all information pertaining to running a collection.<br /><br />_Required_<br />Type: `object` |
|
231 | | 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/](https://schema.getpostman.com/). The value of this property could also be an instance of Collection Object from the [Postman Collection SDK](https://github.com/postmanlabs/postman-collection).<br /><br />As `string`, one can provide a URL where the Collection JSON can be found (e.g. [Postman Cloud API](https://api.getpostman.com/) service) or path to a local JSON file.<br /><br />_Required_<br />Type: `object\|string` [PostmanCollection](https://github.com/postmanlabs/postman-collection/wiki#Collection) |
|
232 | | 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.<br /><br />_Optional_<br />Type: `object\|string` |
|
233 | | 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`.<br /><br />_Optional_<br />Type: `object\|string` |
|
234 | | 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`.<br /><br />_Optional_<br />Type: `number`, Default value: `1` |
|
235 | | options.iterationData | Path to the JSON or CSV file or URL to be used as data source when running multiple iterations on a collection.<br /><br />_Optional_<br />Type: `string` |
|
236 | | options.folder | The name or ID of the folder/folders (ItemGroup) in the collection which would be run instead of the entire collection.<br /><br />_Optional_<br />Type: `string\|array` |
|
237 | | options.timeout | Specify the time (in milliseconds) to wait for the entire collection run to complete execution.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` |
|
238 | | options.timeoutRequest | Specify the time (in milliseconds) to wait for requests to return a response.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` |
|
239 | | options.timeoutScript | Specify the time (in milliseconds) to wait for scripts to return a response.<br /><br />_Optional_<br />Type: `number`, Default value: `Infinity` |
|
240 | | options.delayRequest | Specify the time (in milliseconds) to wait for between subsequent requests.<br /><br />_Optional_<br />Type: `number`, Default value: `0` |
|
241 | | options.ignoreRedirects | This specifies whether newman would automatically follow 3xx responses from servers.<br /><br />_Optional_<br />Type: `boolean`, Default value: `false` |
|
242 | | options.insecure | Disables SSL verification checks and allows self-signed SSL certificates.<br /><br />_Optional_<br />Type: `boolean`, Default value: `false` |
|
243 | | options.bail | A switch to specify whether or not to gracefully stop a collection run (after completing the current test script) on encountering the first error. Takes additional modifiers as arguments to specify whether to end the run with an error for invalid name or path.<br /><br/>Available modifiers: `folder` and `failure`.<br />eg. `bail : ['folder']`<br /><br />_Optional_<br />Type: `boolean\|object`, Default value: `false` |
|
244 | | options.suppressExitCode | If present, allows overriding the default exit code from the current collection run, useful for bypassing collection result failures. Takes no arguments.<br /><br />_Optional_<br />Type: `boolean`, Default value: `false` |
|
245 | | options.reporters | Specify one reporter name as `string` or provide more than one reporter name as an `array`.<br /><br />Available reporters: `cli`, `json`, `junit`, `progress` and `emojitrain`.<br /><br />_Optional_<br />Type: `string\|array` |
|
246 | | options.reporter | Specify options for the reporter(s) declared in `options.reporters`. <br /> e.g. `reporter : { junit : { export : './xmlResults.xml' } }` <br /> e.g. `reporter : { html : { export : './htmlResults.html', template: './customTemplate.hbs' } }` <br /><br />_Optional_<br />Type: `object` |
|
247 | | options.color | Enable or Disable colored CLI output.<br/><br/>Available options: `on`, `off` and `auto`<br /><br />_Optional_<br />Type: `string`, Default value: `auto` |
|
248 | | options.sslClientCert | The path to the public client certificate file.<br /><br />_Optional_<br />Type: `string` |
|
249 | | options.sslClientKey | The path to the private client key file.<br /><br />_Optional_<br />Type: `string` |
|
250 | | options.sslClientPassphrase | The secret client key passphrase.<br /><br />_Optional_<br />Type: `string` |
|
251 | | options.newmanVersion | The Newman version used for the collection run.<br /><br />_This will be set by Newman_ |
|
252 | | callback | Upon completion of the run, this callback is executed with the `error`, `summary` argument.<br /><br />_Required_<br />Type: `function` |
|
253 |
|
254 | ### newman.run~callback(error: _object_ , summary: _object_)
|
255 |
|
256 | The `callback` parameter of the `newman.run` function receives two arguments: (1) `error` and (2) `summary`
|
257 |
|
258 | | Argument | Description |
|
259 | |-----------|---------------|
|
260 | | error | In case newman faces an error during the run, the error is passed on to this argument of callback. By default, only fatal errors, such as the ones caused by any fault inside Newman is passed on to this argument. However, setting `abortOnError:true` or `abortOnFailure:true` as part of run options will cause newman to treat collection script syntax errors and test failures as fatal errors and be passed down here while stopping the run abruptly at that point.<br /><br />Type: `object` |
|
261 | | summary | The run summary will contain information pertaining to the run.<br /><br />Type: `object` |
|
262 | | summary.error | An error object which if exists, contains an error message describing the message <br /><br />Type: `object` |
|
263 | | summary.collection | This object contains information about the collection being run, it's requests, and their associated pre-request scripts and tests.<br /><br />Type: `object` |
|
264 | | summary.environment | An object with environment variables used for the current run, and the usage status for each of those variables.<br /><br />Type: `object` |
|
265 | | summary.globals | This object holds details about the globals used within the collection run namespace.<br /><br />Type: `object` |
|
266 | | summary.run | A cumulative run summary object that provides information on .<br /><br />Type: `object` |
|
267 | | summary.run.stats | An object which provides details about the total, failed, and pending counts for pre request scripts, tests, assertions, requests, and more.<br /><br />Type: `object` |
|
268 | | summary.run.failures | An array of failure objects, with each element holding details, including the assertion that failed, and the request.<br /><br />Type: `array.<object>` |
|
269 | | summary.run.executions | This object contains information about each request, along with it's associated activities within the scope of the current collection run.<br /><br />Type: `array.<object>` |
|
270 |
|
271 | ### newman.run~events
|
272 |
|
273 | Newman triggers a whole bunch of events during the run.
|
274 |
|
275 | ```javascript
|
276 | newman.run({
|
277 | collection: require('./sample-collection.json'),
|
278 | iterationData: [{ "var": "data", "var_beta": "other_val" }],
|
279 | globals: {
|
280 | "id": "5bfde907-2a1e-8c5a-2246-4aff74b74236",
|
281 | "name": "test-env",
|
282 | "values": [
|
283 | {
|
284 | "key": "alpha",
|
285 | "value": "beta",
|
286 | "type": "text",
|
287 | "enabled": true
|
288 | }
|
289 | ],
|
290 | "timestamp": 1404119927461,
|
291 | "_postman_variable_scope": "globals",
|
292 | "_postman_exported_at": "2016-10-17T14:31:26.200Z",
|
293 | "_postman_exported_using": "Postman/4.8.0"
|
294 | },
|
295 | environment: {
|
296 | "id": "4454509f-00c3-fd32-d56c-ac1537f31415",
|
297 | "name": "test-env",
|
298 | "values": [
|
299 | {
|
300 | "key": "foo",
|
301 | "value": "bar",
|
302 | "type": "text",
|
303 | "enabled": true
|
304 | }
|
305 | ],
|
306 | "timestamp": 1404119927461,
|
307 | "_postman_variable_scope": "environment",
|
308 | "_postman_exported_at": "2016-10-17T14:26:34.940Z",
|
309 | "_postman_exported_using": "Postman/4.8.0"
|
310 | }
|
311 | }).on('start', function (err, args) { // on start of run, log to console
|
312 | console.log('running a collection...');
|
313 | }).on('done', function (err, summary) {
|
314 | if (err || summary.error) {
|
315 | console.error('collection run encountered an error.');
|
316 | }
|
317 | else {
|
318 | console.log('collection run completed.');
|
319 | }
|
320 | });
|
321 | ```
|
322 |
|
323 | All events receive two arguments (1) `error` and (2) `args`. **The list below describes the properties of the second
|
324 | argument object.**
|
325 |
|
326 | | Event | Description |
|
327 | |-----------|---------------|
|
328 | | start | The start of a collection run |
|
329 | | beforeIteration | Before an iteration commences |
|
330 | | beforeItem | Before an item execution begins (the set of prerequest->request->test) |
|
331 | | beforePrerequest | Before `prerequest` script is execution starts |
|
332 | | prerequest | After `prerequest` script execution completes |
|
333 | | beforeRequest | Before an HTTP request is sent |
|
334 | | request | After response of the request is received |
|
335 | | beforeTest | Before `test` script is execution starts |
|
336 | | test | After `test` script execution completes |
|
337 | | beforeScript | Before any script (of type `test` or `prerequest`) is executed |
|
338 | | script | After any script (of type `test` or `prerequest`) is executed |
|
339 | | item | When an item (the whole set of prerequest->request->test) completes |
|
340 | | iteration | After an iteration completes |
|
341 | | assertion | This event is triggered for every test assertion done within `test` scripts |
|
342 | | console | Every time a `console` function is called from within any script, this event is propagated |
|
343 | | exception | When any asynchronous error happen in `scripts` this event is triggered |
|
344 | | beforeDone | An event that is triggered prior to the completion of the run |
|
345 | | done | This event is emitted when a collection run has completed, with or without errors |
|
346 |
|
347 |
|
348 |
|
349 | [back to top](#table-of-contents)
|
350 |
|
351 | ## Reporters
|
352 |
|
353 | ### Configuring Reporters
|
354 |
|
355 | - `-r <reporter-name>`, `--reporters <reporter-name>`<br />
|
356 | Specify one reporter name as `string` or provide more than one reporter name as a comma separated list of reporter names. Available reporters are: `cli`, `json`, `junit`, `progress` and `emojitrain`.<br/><br/>
|
357 | Spaces should **not** be used between reporter names / commas whilst specifying a comma separated list of reporters. For instance:<br/><br/>
|
358 | :white_check_mark: `-r cli,json,junit`<br/>
|
359 | :x: `-r cli , json,junit`
|
360 |
|
361 | - `--reporter-{{reporter-name}}-{{reporter-option}}`<br />
|
362 | When multiple reporters are provided, if one needs to specifically override or provide an option to one reporter, this
|
363 | is achieved by prefixing the option with `--reporter-{{reporter-name}}-`.<br /><br />
|
364 | For example, `... --reporters cli,json --reporter-cli-silent` would silence the CLI reporter only.
|
365 |
|
366 | - `--reporter-{{reporter-options}}`<br />
|
367 | If more than one reporter accepts the same option name, they can be provided using the common reporter option syntax.
|
368 | <br /><br />
|
369 | For example, `... --reporters cli,json --reporter-silent` passes the `silent: true` option to both JSON and CLI
|
370 | reporter.
|
371 |
|
372 | **Note:** Sample collection reports have been provided in [examples/reports](https://github.com/postmanlabs/newman/blob/develop/examples/reports).
|
373 |
|
374 | ### CLI Reporter
|
375 | The built-in CLI reporter supports the following options, use them with appropriate argument switch prefix. For example, the
|
376 | option `no-summary` can be passed as `--reporter-no-summary` or `--reporter-cli-no-summary`.
|
377 |
|
378 | 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.
|
379 | However, enabling one or more of the other reporters will result in no CLI output. Explicitly enable the CLI option in
|
380 | such a scenario.
|
381 |
|
382 | | CLI Option | Description |
|
383 | |-------------|-------------------|
|
384 | | `--reporter-cli-silent` | The CLI reporter is internally disabled and you see no output to terminal. |
|
385 | | `--reporter-cli-no-summary` | The statistical summary table is not shown. |
|
386 | | `--reporter-cli-no-failures` | This prevents the run failures from being separately printed. |
|
387 | | `--reporter-cli-no-assertions` | This turns off the output for request-wise assertions as they happen. |
|
388 | | `--reporter-cli-no-success-assertions` | This turns off the output for successful assertions as they happen. |
|
389 | | `--reporter-cli-no-console` | This turns off the output of `console.log` (and other console calls) from collection's scripts. |
|
390 | | `--reporter-cli-no-banner` | This turns off the `newman` banner shown at the beginning of each collection run. |
|
391 |
|
392 | ### JSON Reporter
|
393 | The built-in JSON reporter is useful in producing a comprehensive output of the run summary. It takes the path to the
|
394 | file where to write the report. The content of this file is exactly the same as the `summary` parameter sent to the callback
|
395 | when Newman is used as a library.
|
396 |
|
397 | To enable JSON reporter, provide `--reporters json` as a CLI option.
|
398 |
|
399 | | CLI Option | Description |
|
400 | |-------------|-------------------|
|
401 | | `--reporter-json-export <path>` | Specify a path where the output JSON file will be written to disk. If not specified, the file will be written to `newman/` in the current working directory. If the specified path does not exist, it will be created. However, if the specified path is a pre-existing directory, the report will be generated in that directory. |
|
402 |
|
403 | ### JUNIT/XML Reporter
|
404 | The built-in JUnit reporter can output a summary of the collection run to a JUnit compatible XML file. To enable the JUNIT reporter, provide
|
405 | `--reporters junit` as a CLI option.
|
406 |
|
407 | | CLI Option | Description |
|
408 | |-------------|-------------------|
|
409 | | `--reporter-junit-export <path>` | Specify a path where the output XML file will be written to disk. If not specified, the file will be written to `newman/` in the current working directory. If the specified path does not exist, it will be created. However, if the specified path is a pre-existing directory, the report will be generated in that directory. |
|
410 |
|
411 | Older command line options are supported, but are deprecated in favour of the newer v3 options and will soon be
|
412 | discontinued. For documentation on the older command options, refer to [README.md for Newman v2.X](https://github.com/postmanlabs/newman/blob/release/2.x/README.md).
|
413 |
|
414 | ### HTML Reporter
|
415 | Its an external reporter which can be installed via `npm install -g newman-reporter-html`.
|
416 | The complete installation and usage guide is available at [newman-reporter-html](https://github.com/postmanlabs/newman-reporter-html#readme). Once HTML reporter is installed you can provide `--reporters html` as a CLI option.
|
417 |
|
418 | [back to top](#table-of-contents)
|
419 |
|
420 | ## External Reporters
|
421 |
|
422 | ### Using External Reporters
|
423 | Newman also supports external reporters, provided that the reporter works with Newman's event sequence. Working examples on
|
424 | how Newman reporters work can be found in [lib/reporters](https://github.com/postmanlabs/newman/tree/develop/lib/reporters).
|
425 | For instance, to use the [Newman HTML Reporter](https://github.com/postmanlabs/newman-reporter-html):
|
426 |
|
427 | - Install the reporter package. Note that the name of the package is of the form `newman-reporter-<name>`. The installation should be global if newman is installed globally, local otherwise. (Remove `-g` flag from the command below for a local installation.)<br/>
|
428 | ```console
|
429 | $ npm install -g newman-reporter-html
|
430 | ```
|
431 |
|
432 | - Use the installed reporter, either via the CLI, or programmatic usage. Here, the `newman-reporter` prefix is **not** required while specifying the reporter name in the options.<br/>
|
433 | ```console
|
434 | $ newman run /path/to/collection.json -r cli,html
|
435 | ```
|
436 | ```javascript
|
437 | const newman = require('newman');
|
438 |
|
439 | newman.run({
|
440 | collection: '/path/to/collection.json',
|
441 | reporters: ['cli', 'html']
|
442 | }, process.exit);
|
443 | ```
|
444 |
|
445 | #### Community Maintained Reporters
|
446 | - [HTML](https://github.com/postmanlabs/newman-reporter-html)
|
447 | - [TeamCity](https://github.com/leafle/newman-reporter-teamcity)
|
448 | - [JSON-Light](https://github.com/Paramagnetic/newman-reporter-json-light)
|
449 |
|
450 | ### Creating Your Own Reporter
|
451 | A custom reporter is a Node module with a name of the form `newman-reporter-<name>`. To create a custom reporter:
|
452 | 1. Navigate to a directory of your choice, and create a blank npm package with `npm init`.
|
453 | 2. Add an `index.js` file, that exports a function of the following form:
|
454 | ```javascript
|
455 | function CustomNewmanReporter (emitter, reporterOptions, collectionRunOptions) {
|
456 | // emitter is an event emitter that triggers the following events: https://github.com/postmanlabs/newman#newmanrunevents
|
457 | // reporterOptions is an object of the reporter specific options. See usage examples below for more details.
|
458 | // collectionRunOptions is an object of all the collection run options: https://github.com/postmanlabs/newman#newmanrunoptions-object--callback-function--run-eventemitter
|
459 | }
|
460 | ```
|
461 | 3. Publish your reporter using `npm publish`, or use your reporter locally [see usage instructions](https://github.com/postmanlabs/newman/tree/develop/lib/reporters).
|
462 |
|
463 | Scoped reporter package names like `@myorg/newman-reporter-<name>` are also supported. Working reporter examples can be found in [lib/reporters](lib/reporters).
|
464 |
|
465 | [back to top](#table-of-contents)
|
466 |
|
467 | ## File uploads
|
468 |
|
469 | Newman also supports file uploads for request form data. The files must be present in the
|
470 | current working directory. Your collection must also contain the filename in
|
471 | the "src" attribute of the request.
|
472 |
|
473 | In this collection, `sample-file.txt` should be present in the current working directory.
|
474 | ```json
|
475 | {
|
476 | "info": {
|
477 | "name": "file-upload"
|
478 | },
|
479 | "item": [
|
480 | {
|
481 | "request": {
|
482 | "url": "https://postman-echo.com/post",
|
483 | "method": "POST",
|
484 | "body": {
|
485 | "mode": "formdata",
|
486 | "formdata": [
|
487 | {
|
488 | "key": "file",
|
489 | "type": "file",
|
490 | "enabled": true,
|
491 | "src": "sample-file.txt"
|
492 | }
|
493 | ]
|
494 | }
|
495 | }
|
496 | }
|
497 | ]
|
498 | }
|
499 | ```
|
500 |
|
501 | ```console
|
502 | $ ls
|
503 | file-upload.postman_collection.json sample-file.txt
|
504 |
|
505 | $ newman run file-upload.postman_collection.json
|
506 | ```
|
507 |
|
508 | [back to top](#table-of-contents)
|
509 |
|
510 | ## Using Newman with the Postman API
|
511 |
|
512 | 1 [Generate an API key](https://app.getpostman.com/dashboard/integrations)<br/>
|
513 | 2 Fetch a list of your collections from: `https://api.getpostman.com/collections?apikey=$apiKey`<br/>
|
514 | 3 Get the collection link via it's `uid`: `https://api.getpostman.com/collections/$uid?apikey=$apiKey`<br/>
|
515 | 4 Obtain the environment URI from: `https://api.getpostman.com/environments?apikey=$apiKey`<br/>
|
516 | 5 Using the collection and environment URIs acquired in steps 3 and 4, run the collection as follows:
|
517 | ```console
|
518 | $ newman run "https://api.getpostman.com/collections/$uid?apikey=$apiKey" \
|
519 | --environment "https://api.getpostman.com/environments/$uid?apikey=$apiKey"
|
520 | ```
|
521 |
|
522 | [back to top](#table-of-contents)
|
523 |
|
524 | ## Using Newman in Docker
|
525 | To use Newman in Docker check our [docker documentation](https://github.com/postmanlabs/newman/tree/develop/docker/).
|
526 |
|
527 |
|
528 | ## Migration Guide
|
529 |
|
530 | - [Newman v3 to v4 Migration Guide](MIGRATION.md)
|
531 | - [Newman v3.x Documentation](https://github.com/postmanlabs/newman/blob/release/3.x/README.md)
|
532 |
|
533 |
|
534 | ## Compatibility
|
535 |
|
536 | | Newman | Node |
|
537 | |:-----------------:|:----------:|
|
538 | | v3.x | >= v4.x |
|
539 | | v4.x | >= v6.x |
|
540 |
|
541 | The current Node version compatibility can also be seen from the `engines.node` property in [package.json](https://github.com/postmanlabs/newman/blob/develop/package.json)
|
542 |
|
543 | [back to top](#table-of-contents)
|
544 |
|
545 | ## Contributing
|
546 | Please take a moment to read our [contributing guide](.github/CONTRIBUTING.md) to learn about our development process.
|
547 | Open an [issue](https://github.com/postmanlabs/newman/issues) first to discuss potential changes/additions.
|
548 |
|
549 | ## Community Support
|
550 |
|
551 | <img src="https://avatars1.githubusercontent.com/u/3220138?v=3&s=120" align="right" />
|
552 | If you are interested in talking to the Postman team and fellow Newman users, you can find us on our <a href="https://community.getpostman.com">Postman Community Forum</a>. Feel free to drop by and say hello. You'll find us posting about upcoming features and beta releases, answering technical support questions, and contemplating world peace.
|
553 |
|
554 | Sign in using your Postman account to participate in the discussions and don't forget to take advantage of the <a href="https://community.getpostman.com/search?q=newman">search bar</a> - the answer to your question might already be waiting for you! Don’t want to log in? Then lurk on the sidelines and absorb all the knowledge.
|
555 |
|
556 |
|
557 | ## License
|
558 | This software is licensed under Apache-2.0. Copyright Postdot Technologies, Inc. See the [LICENSE.md](LICENSE.md) file for more information.
|
559 |
|
560 | [![Analytics](https://ga-beacon.appspot.com/UA-43979731-9/newman/readme)](https://www.getpostman.com)
|