How to get response message and response code when assertion fails in jmeter
I am working on testing Webservice using Jmeter. I am using Beanshell Assertion. In this I am trying to display the response code and response message, but the problem is when the request fails. I cannot get an answer. Code | The message displayed on my jmeter log file.In case If I get a correct answer, I get a response code | Message Properly.Is there any solution for getting response code | Message when request fails in jmeter BeanShell Assertion
source to share
There might be something wrong with your Beanshell code, as the Beanshell Assertion should usually handle the failure of the parent sampler
The code that generated these log lines looks as simple as:
StringBuilder sb = new StringBuilder();
sb.append("Sampler: ");
sb.append(SampleResult.getSampleLabel()).append(" ");
sb.append("Successful: ");
sb.append(SampleResult.isSuccessful()).append(" ");
sb.append("Code: ");
sb.append(ResponseCode).append(" ");
sb.append("Message: ");
sb.append(ResponseMessage);
log.info(sb.toString());
A few tips:
- Add statement
debug();
as first line of your Beanshell statement and check STDOUT for details. -
Wrap your code in try / catch block and in catch block block exception from jmeter.log file like
try { //your Beanshell Assertion code here } catch (Throwable ex) { log.error("Something went wrong", ex) }
- See How to Use BeanShell: JMeter's Favorite Built-in Component for details on correct Beanshell scripting in JMeter.
source to share