2

Obviously, I know that I have response time in .jtl file and in listener called Aggregate report, but I'm looking for way to get reponse time of request to variable.

Kac
  • 184
  • 3
  • 15

1 Answers1

2

You can do it as follows:

  1. Add Beanshell PostProcessor as a child of the request
  2. Put the following code into PostProcessor's "Script" area:

    vars.put("responseTime", String.valueOf(prev.getTime()));
    

It will get elapsed time for the sampler (in milliseconds) and store it into ${responseTime} variable. You can add sampler label as prefix or postfix to distinguish response times for different samplers.

prev is a shorthand for parent SampleResult instance.

See How to Use BeanShell: JMeter's Favorite Built-in Component for comprehensive information on Beanshell scripting in JMeter tests.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you , it's exatcly what I was looking for, but generally I've got question : Why did you use , String.valueOf before (prev.getTime), Does it necessary? – Kac Jan 18 '16 at 12:32
  • There are 2 methods: `vars.put(String, String)` - in that case cast to string is mandatory, and `vars.put(String, Object)` - cast is not necessary. See [JMeterVariables class JavaDoc](https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html) - `vars` is a shorthand to its instance – Dmitri T Jan 18 '16 at 13:38
  • Dmitri, tkank You for explanation, this solution is correct when I want to get response time of previous request,but now I wonder how to get response time for whole sample , in my case for Transaction controller, which consist of three requests? – Kac Jan 25 '16 at 10:05