Post

Newman

Running Postman collections via Newman from the command line, including data-driven tests using JSON files and HTML report generation.

The following command runs a Postman collection through Newman with a data file for iteration, generates both CLI and HTML reports, and passes an access token as an environment variable. This is useful for automating API tests in CI/CD pipelines.

1
2
3
4
5
6
7
newman run \
-d postman/vlans-post.json \
--reporters=cli,htmlextra  \
--env-var access_token=$TOKEN \
--folder '/vlans-post' \
--reporter-htmlextra-export newman/network.html  \
--verbose  postman/postman_collection_v5.json

I have a collection in Postman which loads “payload objects” from a JSON file and want to make it run in Newman from the command line.

POST request

Body: of POST request I have got ``

Pre-request Script: logically pm.globals.set("jsonBody", JSON.stringify(pm.iterationData.toObject()));

And a file.json file with this kind of “objects”:

The data file contains an array of objects, where each object represents one iteration of the collection run. Newman will iterate over each entry and substitute the values into your Postman requests.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[
    {
    "data": {
        "propert1": 24,
        "property2": "24__DDL_VXS",
        ...
    },
        {
    "data": {
        "propert1": 28,
        "property2": "28__HDL_VDS",
        ...
    }
...
]

Works like a charm in Postman.

Here is what I’m trying to run in the terminal.

1
2
3
4
5
newman run \
-d file.json  \
--env-var access_token=$TOK4EN \
--folder '/vlanspost' \
postman/postman_collection_v2.json

Based on the results I am getting - it looks like

This post is licensed under CC BY 4.0 by the author.