-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Newman Run Events
Newman's run method triggers a bunch of events during the run. These events allow building complex workflows in a collection execution lifecycle.
newman.run returns an event emitter instance where you can attach listeners using the .on or .once methods.
Example:
const newman = require('newman');
newman
.run({ collection: require('/path/to/collection.json') })
.on('done', (err, args) => { /* result: args.run */ })
.on('console', (err, args) => { /* logs: args.messages */ })
//.on('<event-name>', (err, args) => { /* event handler */ })Every event handler (callback function) is called with two arguments:
-
err- The first argument is anErrorinstance, if an error occurred, otherwise it's alwaysnull -
args- The second argument is anObjecthaving event-specific properties
The list below describes the events and their args properties in detail.
Triggered once at the start of a collection run
| Property | Description |
|---|---|
cursor |
Cursor Object |
Before an iteration commences
| Property | Description |
|---|---|
cursor |
Cursor Object |
Before an item execution begins (the set of
prerequest->request->test)
| Property | Description |
|---|---|
cursor |
Cursor Object |
item |
Item instance |
Before pre-request script execution starts
| Property | Description |
|---|---|
cursor |
Cursor Object |
events |
An array of Event |
item |
Item instance |
After pre-request script execution completes
| Property | Description |
|---|---|
cursor |
Cursor Object |
executions |
An array of executions object |
item |
Item instance |
Before an HTTP request is sent
| Property | Description |
|---|---|
cursor |
Cursor Object |
request |
Request instance |
item |
Item instance |
After the response of the request is received
| Property | Description |
|---|---|
cursor |
Cursor Object |
response |
Response instance |
request |
Request instance |
item |
Item instance |
cookies |
CookieList instance |
Before test script execution starts
| Property | Description |
|---|---|
cursor |
Cursor Object |
events |
An array of Event |
item |
Item instance |
After test script execution completes
| Property | Description |
|---|---|
cursor |
Cursor Object |
executions |
An array of executions object |
item |
Item instance |
Before any script (of type
testorprerequest) is executed
| Property | Description |
|---|---|
cursor |
Cursor Object |
script |
Script instance |
event |
Event instance |
item |
Item instance |
After any script (of type
testorprerequest) is executed
| Property | Description |
|---|---|
cursor |
Cursor Object |
execution |
Executions object |
script |
Script instance |
event |
Event instance |
item |
Item instance |
When an item (the whole set of
prerequest->request->test) completes
| Property | Description |
|---|---|
cursor |
Cursor Object |
item |
Item instance |
After an iteration completes
| Property | Description |
|---|---|
cursor |
Cursor Object |
When test assertion is done within the scripts
| Property | Description |
|---|---|
cursor |
Cursor Object |
assertion |
Assertion name or message |
skipped |
Is the assertion skipped |
error |
Assertion error on failure |
item |
Item instance |
When a console function is called within the scripts
| Property | Description |
|---|---|
cursor |
Cursor Object |
level |
Console log level type |
messages |
Array of messages |
When an asynchronous error happens during script execution
| Property | Description |
|---|---|
cursor |
Cursor Object |
error |
Error Object |
Before the completion of the run
| Property | Description |
|---|---|
cursor |
Cursor Object |
summary |
Summary Object |
After the completion of the run, with or without errors
| Property | Description |
|---|---|
collection |
Collection used in the run |
environment |
VariableScope instance with the environment variables used in the run |
globals |
VariableScope instance with the global variables used in the run |
run |
Run summary object |