How can we see which requests had failed tests?

Hi, we have some tests per requests but are unable to see which requests had these failed tests.

image

--http-debug didn’t help. Any tip how we can see specifically which requests had failed tests?

Thanks

check() returns true if all of the conditions passed, or false if any one failed, so you can use that to console.log() (or emit in a custom metric) the responses which failed to pass the checks. Like this:


import http from "k6/http";
import { sleep, check } from "k6";
import { Counter } from 'k6/metrics';

let errors_metrics = new Counter("my_errors");

export default function () {
    let resp = http.get("https://httpbin.test.k6.io/status/400/");

    let passed = check(resp, {
        "http2 is used": (r) => r.proto === "HTTP/2.0",
        "status is 200": (r) => r.status === 200,
        "content is present": (r) => r.body.indexOf("whatever") !== -1,
    })

    if (!passed) {
        console.log(`Request to ${resp.request.url} with status ${resp.status} failed the checks!`);
        errors_metrics.add(1, { url: resp.request.url });
    }
}

You can find all properties of the Response object here: https://k6.io/docs/javascript-api/k6-http/response-k6-http

1 Like