Newman html extra report with custom hbs

Postman team

I am using html extra report with custom hbs shared by one your team members. Here is the code snippet. I would like to see all the available response objects for each execution. Please share the documentation where I can see all the available objects to use.
I am using response.responseTime to get response time of each request. Is this a correct attribute?

{{#each aggregations}}
{{#each executions}}


{{item.name}}
{{response.responseTime}}

Thanks

Hey @rjayaram

It’s a little unclear what you’re asking but I’ll have a go at showing you something and hope that points you in the right direction.

To just get a list of the different requests in a Collection and their individual timings on a static HTML page, you could use something simple like this code. If you save this as a .hbs file and reference this on the Newman run command, it will produce a report with those details.

<html>
  <head>
    <title>Timings Template</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  </head>
  <body>
  <div class="container">
    <div class="table-responsive">
      <table class="table table-striped table-bordered">
          <thead class="thead-inverse">
              <tr class="text-center">
                  <th class="text-uppercase">Request Name</th>
                  <th class="text-uppercase">Timing (ms)</th>
              </tr>
          </thead>
          <tbody>
          {{#each aggregations}}
          {{#each executions}}
              <tr>
                  <td class="text-center">{{item.name}}</td>
                  <td class="text-center">{{response.responseTime}}</td>
              </tr>
          {{/each}}
          {{/each}}
          </tbody>
      </table>
    </div>
  </div>
  </body>
</html>

The final report for the code above will look something like this:

It’s bringing in some of the Bootstrap styling and classes to make it look a little better on the eye but the detail is there for you to see. :slight_smile:

In terms of what’s available in the summary object - If you look through the JSON below, you will able to see the different things that could be extracted and displayed on a report if you referenced them in the .hbs file. I’ve removed some of the output for better readability but you should get the general feel for what’s in there.

{
  "cursor": {
"position": 0,
"iteration": 0,
"length": 1,
"cycles": 1,
"empty": false,
"eof": false,
"bof": true,
"cr": false,
"ref": "bd083954-07e2-446e-bb70-69da2da31fb4"
  },
  "summary": {
"collection": {
  "_": {
    "postman_id": "23b98424-d2c0-4c7d-800e-0bd841eb8495"
  },
  "item": [
    {
      "id": "0da45a06-a755-4b19-b1bf-5951ec03c449",
      "name": "Simple GET Request",
      "request": {
        "url": {
          "protocol": "https",
          "path": [
            "posts"
          ],
          "host": [
            "jsonplaceholder",
            "typicode",
            "com"
          ],
          "query": [],
          "variable": []
        },
        "method": "GET",
        "body": {}
      },
      "response": [],
      "event": [
        {
          "listen": "test",
          "script": {
            "id": "9e34f1b9-b071-4bbc-b033-14912e39fdd8",
            "type": "text/javascript",
            "exec": [
              "pm.test(\"Status code is 200\", function () {",
              "    pm.response.to.have.status(200);",
              "});",
              "",
              "pm.test(\"Response time is less than 200ms\", function () {",
              "    pm.expect(pm.response.responseTime).to.be.below(200);",
              "});"
            ],
            "_lastExecutionId": "0e68fabd-3f30-49d5-9afe-009e11490f6b"
          }
        }
      ]
    }
  ],
  "event": [],
  "variable": [],
  "info": {
    "_postman_id": "23b98424-d2c0-4c7d-800e-0bd841eb8495",
    "name": "Demo Collection",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  }
},
"environment": {
  "id": "7e020029-b23d-40a3-9fb6-280a7bc93e93",
  "values": []
},
"globals": {
  "id": "f267c3f2-0ed2-451f-8b2e-f02fd133ec06",
  "values": []
},
"run": {
  "stats": {
    "iterations": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "items": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "scripts": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "prerequests": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "requests": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "tests": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "assertions": {
      "total": 2,
      "pending": 0,
      "failed": 0
    },
    "testScripts": {
      "total": 1,
      "pending": 0,
      "failed": 0
    },
    "prerequestScripts": {
      "total": 0,
      "pending": 0,
      "failed": 0
    }
  },
  "timings": {
    "responseAverage": 89,
    "responseMin": 89,
    "responseMax": 89,
    "responseSd": 0,
    "dnsAverage": 0,
    "dnsMin": 0,
    "dnsMax": 0,
    "dnsSd": 0,
    "firstByteAverage": 0,
    "firstByteMin": 0,
    "firstByteMax": 0,
    "firstByteSd": 0,
    "started": 1556096542737
  },
  "executions": [
    {
      "cursor": {
        "position": 0,
        "iteration": 0,
        "length": 1,
        "cycles": 1,
        "empty": false,
        "eof": false,
        "bof": true,
        "cr": false,
        "ref": "f3fc4502-5221-4574-a2dc-126888377ac1",
        "httpRequestId": "f66f4935-10f8-4ef2-8105-f43f4882c481"
      },
      "item": {
        "id": "0da45a06-a755-4b19-b1bf-5951ec03c449",
        "name": "Simple GET Request",
        "request": {
          "url": {
            "protocol": "https",
            "path": [
              "posts"
            ],
            "host": [
              "jsonplaceholder",
              "typicode",
              "com"
            ],
            "query": [],
            "variable": []
          },
          "method": "GET",
          "body": {}
        },
        "response": [],
        "event": [
          {
            "listen": "test",
            "script": {
              "id": "9e34f1b9-b071-4bbc-b033-14912e39fdd8",
              "type": "text/javascript",
              "exec": [
                "pm.test(\"Status code is 200\", function () {",
                "    pm.response.to.have.status(200);",
                "});",
                "",
                "pm.test(\"Response time is less than 200ms\", function () {",
                "    pm.expect(pm.response.responseTime).to.be.below(200);",
                "});"
              ],
              "_lastExecutionId": "0e68fabd-3f30-49d5-9afe-009e11490f6b"
            }
          }
        ]
      },
      "request": {
        "url": {
          "protocol": "https",
          "path": [
            "posts"
          ],
          "host": [
            "jsonplaceholder",
            "typicode",
            "com"
          ],
          "query": [],
          "variable": []
        },
        "header": [
          {
            "key": "User-Agent",
            "value": "PostmanRuntime/7.11.0",
            "system": true
          },
          {
            "key": "Accept",
            "value": "*/*",
            "system": true
          },
          {
            "key": "Cache-Control",
            "value": "no-cache",
            "system": true
          },
          {
            "key": "Postman-Token",
            "value": "f353da91-8582-4b7d-ba2f-6df59ae72352",
            "system": true
          },
          {
            "key": "Host",
            "value": "jsonplaceholder.typicode.com",
            "system": true
          },
          {
            "key": "accept-encoding",
            "value": "gzip, deflate",
            "system": true
          },
          {
            "key": "Connection",
            "value": "keep-alive",
            "system": true
          }
        ],
        "method": "GET",
        "body": {}
      },
      "response": {
        "id": "725409e4-f2aa-4a67-8b8e-13bf71176323",
        "status": "OK",
        "code": 200,
        "header": [
          {
            "key": "Date",
            "value": "Wed, 24 Apr 2019 09:02:22 GMT"
          },
          {
            "key": "Content-Type",
            "value": "application/json; charset=utf-8"
          },
          {
            "key": "Transfer-Encoding",
            "value": "chunked"
          },
          {
            "key": "Connection",
            "value": "keep-alive"
          },
          {
            "key": "Set-Cookie",
            "value": "__cfduid=d9f98a699fa338b00c9745fda3a77fc3c1556096542; expires=Thu, 23-Apr-20 09:02:22 GMT; path=/; domain=.typicode.com; HttpOnly"
          },
          {
            "key": "X-Powered-By",
            "value": "Express"
          },
          {
            "key": "Vary",
            "value": "Origin, Accept-Encoding"
          },
          {
            "key": "Access-Control-Allow-Credentials",
            "value": "true"
          },
          {
            "key": "Cache-Control",
            "value": "public, max-age=14400"
          },
          {
            "key": "Pragma",
            "value": "no-cache"
          },
          {
            "key": "Expires",
            "value": "Wed, 24 Apr 2019 13:02:22 GMT"
          },
          {
            "key": "X-Content-Type-Options",
            "value": "nosniff"
          },
          {
            "key": "Etag",
            "value": "W/\"6b80-Ybsq/K6GwwqrYkAsFxqDXGC7DoM\""
          },
          {
            "key": "Content-Encoding",
            "value": "gzip"
          },
          {
            "key": "Via",
            "value": "1.1 vegur"
          },
          {
            "key": "CF-Cache-Status",
            "value": "HIT"
          },
          {
            "key": "Expect-CT",
            "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
          },
          {
            "key": "Server",
            "value": "cloudflare"
          },
          {
            "key": "CF-RAY",
            "value": "4cc6e5e098d534b8-LHR"
          }
        ],
        "stream": {
          "type": "Buffer",
          "data": []
        },
        "cookie": [],
        "responseTime": 89,
        "responseSize": 27520
      },
      "id": "0da45a06-a755-4b19-b1bf-5951ec03c449",
      "assertions": [
        {
          "assertion": "Status code is 200",
          "skipped": false
        },
        {
          "assertion": "Response time is less than 200ms",
          "skipped": false
        }
      ]
    }
  ],
  "transfers": {
    "responseTotal": 27520
  },
  "failures": [],
  "error": null
}
  }
}

Hopefully, that helps you but if you’re still unsure what’s going on, I’d be more than happy to answer more questions. This will be a good thread for other people looking to do the same / a similar thing on the HTML reports.

Hi

Thanks for the reply.

  1. As I mentioned earlier I am using response.responseTime to get response time of each request. Based on your example above my understanding is it is the right attribute to get the response time of each request.

  2. I was also asking for documentation on all the available attributes for execution and summary objects. You have shared the JSON for summary objects above. Pl share the links for execution object as well.

Thanks

The only thing that would help you create a new template is the handlebars documentation. This is the syntax that you’re using to reference different parts of the Newman summary object.

The JSON output I posted is the actual processed data, from a Collection, that I ran with Newman. The values from that were used to create the final report.

If you look down through the JSON, you will see the response object which contains the responseTime property, with the value 89 - That’s what would be displayed on the HTML report when using the {{response.responseTime}} syntax.

All of this is within the executions array and that’s why we need to loop through the array with the {{#each executions}} handlebars syntax to get the individual requests.

If you take a look at this template file, you should be able to see the handlebar syntax and match it up to the JSON.

Thanks. I do see execution attributes in your Json. I did not scroll the text earlier. I can see all the objects. This ticket can be closed.