Is there any way for k6
to save every response body and response code of the failed checks/assertion?
maybe something like
check(res, {"rc code": (r) => r.status == rc_code,}) || AppendErrorLog(filename, r.body);
Unfortunately not, at the moment you can't open files outside of the init context, and even then they are read-only.
As a workaround, you can use console.log()
to output the response body and redirect the stderr
stream to a file.