How to print debug info only for failed tests/checks?


I am using postman-to-k6 conversion tool to generate k6_script.
One of the test 6.4 p0 performance public/game/list Response time is less than 200ms is failing due to slow response time. I am having issue debugging only failed test request

How can I print header “Correlationid” only for failed tests ?

postman test


k6 converted code as follows

    name: "6.4 p0 performance public/game/list",
    id: "3e6a4fce-04e7-4aba-b022-d164c10037ef",
    method: "GET",
    address: "{{catalogueurl}}/public/game/list?limit=20",
    post(response) {
        "6.4 p0 performance public/game/list test for 200 response code public/game/list",
        function() {

        "6.4 p0 performance public/game/list Response time is less than 200ms",
        function() {

In order to debug failed test request I am using –http-debug option for k6 but it prints out all request info rather than only failed ones.

This is how I am running the k6 command
k6 run -vu 20 --iterations 100 --out influxdb=http://influx:8086/mydevk6db k6_script.js --http-debug="X-Correlationid"

sample debug info:

GET /public/game/list?limit=20 HTTP/1.1
Host: catalogueurl
User-Agent: k6/0.26.2 (
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

HTTP/2.0 200 OK
Content-Length: 64644
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Fri, 12 Jun 2020 04:46:33 GMT
Etag: W/"fc84-aLmj2GeK2EE8KYCmLlO06jz3FYs"
X-Correlationid: 7eae9735-3f88-49c3-9c29-226d9555f5ef
X-Frame-Options: SAMEORIGIN
X-Requestid: 401212d6-9a2d-4b67-967f-3b1cfb31ef50
done [==========================================================] 100 / 100

    ✓ 6.4 p0 performance public/game/list response should be okay to process
    ✓ 7.1 p1 public/category/read Status code is 200
    ✓ 7.8 p0 performance public/news/list test 200 for rss service public/news/list
    ✓ test for 200 response code public/comment/latest
    ✓ 3.1 p1 public/banner Status code is 200
    ✓ 6.4 p0 performance public/game/list test for 200 response code public/game/list
    ✓ 6.4 p0 performance public/game/list Body matches string
    ✗ 6.4 p0 performance public/game/list Response time is less than 200ms**
     ↳  25% — ✓ 25 / ✗ 75
    ✓ 7.5 p0 performance public/news/read test 200 for rss service public/news/read
    ✓ 5.1 p1 public/result/page/settings Status code is 200

    checks.....................: 92.50% ✓ 925  ✗ 75
    data_received..............: 9.4 MB 2.0 MB/s
    data_sent..................: 236 kB 49 kB/s
    http_req_blocked...........: avg=9.4ms    min=0s       med=0s       max=184.64ms p(90)=36.03ms  p(95)=45.92ms
    http_req_connecting........: avg=1.73ms   min=0s       med=0s       max=29.66ms  p(90)=9.3ms    p(95)=13.37ms
    http_req_duration..........: avg=117.36ms min=7.78ms   med=29.04ms  max=1.28s    p(90)=336.32ms p(95)=514.44ms
    http_req_receiving.........: avg=16.49ms  min=25µs     med=63µs     max=935.93ms p(90)=12.8ms   p(95)=20.55ms
    http_req_sending...........: avg=76.14µs  min=37µs     med=58µs     max=2.19ms   p(90)=123.1µs  p(95)=146µs
    http_req_tls_handshaking...: avg=7.6ms    min=0s       med=0s       max=169.99ms p(90)=24.05ms  p(95)=29.34ms
    http_req_waiting...........: avg=100.79ms min=7.2ms    med=27.38ms  max=1.09s    p(90)=307.06ms p(95)=424.01ms
    http_reqs..................: 700    145.017249/s
    iteration_duration.........: avg=897.86ms min=198.99ms med=710.61ms max=2.26s    p(90)=1.97s    p(95)=2.23s
    iterations.................: 100    20.71675/s
    vus........................: 20     min=20 max=20
    vus_max....................: 20     min=20 max=20

Hi @dipeshlshah,

I am not familiar with how postman-to-k6 does it’s thing, but you can just check the value with an if and print the value :smiley:

I expect that you can do that after(or before) the line


such as

          if (pm.response.responseTime >= 200) {
               console.log(pm.response.headers["X-Correlationid"]); // you can print whatever

I am not certain what fields pm.response have though as that is something coming from postman-to-k6 but there should be headers somewhere :smiley:

Good luck!

I already knew that from
But I still tried that and getting error. Can you please suggest @mstoykov

ERRO[0007] Error: pm.response.headers not supported
	at executePostrequest (file:///Users/work/load_test/libs/shim/core.js:1196:203(90))
	at executeRequest (file:///Users/work/load_test/libs/shim/core.js:985:25(128))
	at executeRequest (file:///Users/work/load_test/libs/shim/core.js:966:251(57))
	at file:///Users/work/load_test/libs/shim/core.js:307:46(35)

Maybe see if postman[Request](...) returns a response object.

The k6 response has headers but the postman-to-k6 does A LOT of wrapping of stuff. But it seems like it does return the k6 response object after all.

Hi @dipeshlshah!

I’ll have a look and get back to you.


Could you please try switching



1 Like

This has worked like a charm! Thanks a ton @simme

I have researched a bit and found out that we can also fix pm.response.headers issue by following patch libs/shim/core.js in postman-to-k6 tool. Thoughts ?

get headers() {
      // throw new Error('pm.response.headers is not supported');
      return {
        get: function(name) { 
          return store.response.headers.uncased[name.toLowerCase()];
1 Like

Might very well be possible! Feel free to create an issue in and I’ll have a look as soon as time allows!