I'm trying to correlate the response statusCode with the response body.
How can I get a log of the body & the statusCode? I attempted this:
...blah
scenarios:
- name: POST /foo
flow:
...blah
- post:
url: "/foo"
capture:
- json: "$"
as: fooBody
...blah
- log: "{{statusCode}} => {{ fooBody }}"
Obviously statusCode logs as undefined. The fooBody works.
There's no way to capture the response code at the moment. You have two options that may help:
artillery with DEBUG=http,http:response to print the details of every HTTP request madeafterResponse function which will have access to the full response object. That way you can output the information you need in any way you like, save it to a file if needed etc.Thanks for the response @hassy
Unfortunately using the additional DEBUG settings only added headers.
For example,
Thu, 14 Feb 2019 16:53:35 GMT http:response {
"content-type": "application/json",
"content-length": "32",
"connection": "keep-alive",
"date": "Thu, 14 Feb 2019 16:53:35 GMT",
"x-amzn-requestid": "omitted",
"x-amzn-errortype": "TooManyRequestsException",
"x-amz-apigw-id": "omitted",
"x-cache": "Error from cloudfront",
"via": "1.1 omitted.cloudfront.net (CloudFront)",
"x-amz-cf-id": "omitted=="
}
Thu, 14 Feb 2019 16:53:35 GMT http:response {
"message": "Too Many Requests"
}
Yeah, I discovered earlier this week that DEBUG=http:response doesn't actually print out the HTTP response status code. That's the single most important part of any response, in my opinion.
If you add processor: "./my-functions.js" into your test.yml files config then add afterResponse: "printStatus" to your call in the flow like
- get:
url: "/login"
afterResponse: "printStatus"
then in the my-functions.js file add a
function printStatus (requestParams, response, context, ee, next) {
console.log(`${response.statusCode.uri.path}: ${response.statusCode}`);
return next();
}
make sure in the file you include
module.exports = {
printStatus: printStatus
}
Thanks for the example @JGro144!
I had to make a small modification to get it to work: ( replace statusCode with request to retrieve uri path. )
function printStatus (requestParams, response, context, ee, next) {
console.log(`${response.request.uri.path}: ${response.statusCode}`);
return next();
}
Most helpful comment
If you add
processor: "./my-functions.js"into your test.yml files config then addafterResponse: "printStatus"to your call in the flow likethen in the my-functions.js file add a
make sure in the file you include