I am working on Webservice Testing 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 am unable to get the response Code|Message displayed on my jmeter log file.In case If I get the Proper response I am getting the Response Code|Message Properly.Is there any solution to get the Response Code|Message when the Request Fails in jmeter BeanShell Assertion
Asked
Active
Viewed 5,348 times
2 Answers
0
Perhaps something is wrong with your Beanshell code as Beanshell Assertion should normally handle parent sampler failure
The code which produced 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());
Few tips:
- Add
debug();
statement as 1st line of your Beanshell Assertion and inspect STDOUT for details Surround your code in try/catch block and in the catch block print exception to jmeter.log file as
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 guide for details on proper Beanshell scripting in JMeter.

Dmitri T
- 159,985
- 5
- 83
- 133
-
thanks Dmitri T.based on your code i was able to find out the problem. – RCBian Jul 09 '15 at 08:17
-
Is It possible to get the assertion Failure message that is displayed in the View Result Tree to be stored into a String Variable – RCBian Jul 09 '15 at 08:19
-
just use `vars.put("variable_name", "variable_value");` stanza – Dmitri T Jul 09 '15 at 14:40