loggingjmeterresponse

Jmeter - how to log "response body" in the log file


I've an issue with my project. I'm trying to log the response body and cheking it in the generated report. But I can't see the corresponding column:

timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect

I tryed to do this:

  1. JSR223 PostProcessor whit this:
def responseBody = prev.getResponseDataAsString();
vars.put("responseBody", responseBody);
  1. BeanShell Sampler with this:
import org.apache.jmeter.samplers.SampleResult;

SampleResult.setResponseData(vars.get("responseBody").getBytes());

IMPORTANT: I'm executing the project in CLI mode

But it didn't work

Anybody can help me? I will be grateful

Thanks...

Expected results: timeStamp,elapsed,label,responseCode,responseMessage, responseBody,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect


Solution

  • In order to add an extra column to the .jtl results file containing a JMeter Variable value you need to declare the relevant Sample Variable

    Either run JMeter providing the Sample Variable name via -J command line argument:

    jmeter -Jsample_variables=responseBody -n -t test.jmx -f -l result.jtl
    

    or in order to make the change permanent add the next line to user.properties file:

    sample_variables=responseBody
    

    More information: