Checks names and count in the output

Hello team,

Hope everyone is doing well. I am trying to get the checks names and count in the logs other than percentage. Kindly assist me with this.

Hi @Niveditha !

I’m not sure if I understood the question. Could you please elaborate and maybe provide any example?

Thanks!

Hi, olegbespalov

Thanks for the reply. Here I want the name, count and status of checks in logs.

Example:

Check_Name: Responce Code was 200
Count: 10
Status: Pass or Fail

Okay, you can try to use the Custom summary.

For instance, script like:

import http from 'k6/http';
import { check } from 'k6';

export default function () {
  const res = http.get('http://httpbin.test.k6.io');
  check(
    res,
    {
      'response code was 200': (res) => res.status == 200,
      'body size was 1234 bytes': (res) => res.body.length == 1234,
    }
  );

}

export function handleSummary(data) {
  console.log('Preparing the end-of-test summary...');

  console.log(data.root_group.checks);
}

will output something like:

 k6 run script.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: script.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)


running (00m00.9s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.9s/10m0s  1/1 iters, 1 per VU
INFO[0001] Preparing the end-of-test summary...          source=console
INFO[0001] [{"id":"bed5ed4407a904e0b27ca293ed585e5e","passes":1,"fails":0,"name":"response code was 200","path":"::response code was 200"},{"path":"::body size was 1234 bytes","id":"fd85ec39d0759bbfaa34a5fb1f00b4bc","passes":0,"fails":1,"name":"body size was 1234 bytes"}]  source=console

Let me know if that helps,
Cheers!