4

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

RCBian
  • 1,080
  • 2
  • 20
  • 31

2 Answers2

0

Perhaps something is wrong with your Beanshell code as Beanshell Assertion should normally handle parent sampler failure

Beanshell Assertion example

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:

  1. Add debug(); statement as 1st line of your Beanshell Assertion and inspect STDOUT for details
  2. 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)
    }
    
  3. 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
0

You can also use a their standard listener

Add "View Results Tree"

Islam Murtazaev
  • 1,488
  • 2
  • 17
  • 27