We have a HTTP monitor and in the post-execution script of one of the requests, we do a simple response validation.
var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);
if((jsonData.value.length == 0)) {
api.fail(“Unexpected response”);
}
However this step consistently fails. I have extracted the response from the monitor execution details ad tried to parse in JS runtime(chrome, nodejs) and there JSON.parse works without any problems. I am not sure what is causing this problem on DT as especially in the event section, I only see “Script execution failed” without further context.
for future test remember you can allways use the error to see the full body in the response to know if the problem its for the logic or for the values in the body
some aproach:
var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);
var datastringify = JSON.stringify(jsonData);
if (response.getStatusCode() != 200) {
api.fail("HTTP error:" + datastringify );
}