I am using JMeter as a unit test tool, in parameterised calls where I expect some of the responses to be 500 internal server errors. I am using BeanShell Assertions to check the responses.
I want some of the 500 internal server errors to NOT be marked as failures if the response contains a specified text. All 500 server errors are marked as failures. Is it possible to change the behavior?
Below is an extract from the BeanShell Assertion.
if (ResponseCode.equals("500")) {
Failure = false;
String respData = new String(ResponseData);
if (! respData.contains("specific Text")) {
Failure = true;
FailureMessage = "500 Internal Server Error: Unexpected Response. " +
"Response Message: " + respData;
}
}
Thank you and Regards
UPD: please find most simple & “native” solution below:
In case if you want to do some tricky things in code use the following approach.
Access and modify SampleResult to change the status from “FAIL” to “PASS” if the code is 500 from your JSR223 Assertion or use JSR223 PostProcessor instead – they all have access to SampleResult Object.
1. JSR223 Assertion
2. JSR223 PostProcessor
Use
previnstead – to access SampleResult object of the sampler to which one post-processor is attached: