Display Response Body on the report JMeter - jmeter

I try to show a script result on the report
Hello all,
I have written a test where I am trying to determine the total duration of a thread.
I calculate the time with JSR223 script:
[]
This is my result:
[]
The results are calculated correctly, but on the HTML report I have only the time from the request.
[]
[]
Does anyone know how I pass the calculated time from the ResponseBody?
Thank you very much.

If you want to set your JSR223 Sampler execution time to the value of your JSR223 Sampler result text you need to use JSR223 PostProcessor and the following code:
prev.elapsedTime = prev.getResponseDataAsString() as long
where prev stands for the previous SampleResult, see JavaDoc for all functions available with descriptions and Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands available for the JSR223 Test Elements.
also remove this /1000 bit from your JSR223 Sampler code as JMeter elapsed time is in milliseconds, if you want it to be in seconds - round it up so it won't have any decimal points.

Related

JMeter et Latency of the last Request

Is there any way to get the latency (i.e. duration) of the last request? I need this, because I want to wait e.g. 10 seconds - duration-of-last-request seconds. But for this I need the time taken by the last sampler/http request. How do I get this?
Take a look at JSR223 PostProcessor, the relevant code would be something like:
sleep 10000L - prev.getTime()
where prev stands for the previous SampleResult, see the JavaDoc for comprehensive information on all methods/fields and Top 8 JMeter Java Classes You Should Be Using with Groovy for other useful JMeter API shorthands available for the JSR223 Test Elements

How to execute a BeanShell PostProcessor after all samples end on Jmeter?

My goal is make a beautiful report about my test plan. I'm using about 50 threads and infinite loop so I want get the responses content and make the report. The problem is that the PostProcessor execute every sample request end so I can't put it all together on the same context to use all data and if I use the data every sample ends the results becomes a big mess. I don't found the solution on the web and I'm newbie with Jmeter. So, there are a way to wait all threads ends and get all responses data on 1x time ?
First of all don't use Beanshell, since JMeter 3.1 you should switch to JSR223 Test Elements and Groovy language
If you need to collect response data the best option is writing it into a file using i.e. Flexible File Writer and if any post-processing is needed you can perform this using JSR223 Sampler in the tearDown Thread Group

jmeter - How to ignore selected samplers from getting measured in the *jtl file

My test configuration :
Loop Controller
--> Beanshell Sampler
vars.put("test", "${__CSVRead(*test,0)}");
Add it to an existing array retrieved from vars.getObject
In the above scenario, I am constructing my request payload dynamically in a loop controller. I had to put the CSVRead function in a separate Beanshell sampler under the loop controller since "${__CSVRead(*test,0)}" was reading the sample line if I use it within a for loop inside the beanshell sampler (interpreted mode).
While the above configuration meets my requirement, my *.jtl files are growing in size even for a 30 minute load test since the BeanShell sampler is getting measured all the time. While I am able to filter the required data by using the FilterResults tool, I want to know how to avoid this during the execution itself like the TestActionSampler
Use one of the following Test Elements instead:
BeanShell PreProcessor
BeanShell PostProcessor
Beanshell Timer
By default Timers and Pre/Post Processors execution time is not included into parent sampler elapsed time (unless you use Transaction Controller explicitly configured to do so), using this approach you will be able to exclude the time, required for constructing payload from test results.
I resolved it by using the following configuration.
Loop Controller
--> Test Action Sampler
--> Beanshell timer returning 0 at the end
vars.put("test", "${__CSVRead(*test,0)}");
Add it to an existing array retrieved from vars.getObject
return 0;

If it possible to get average response time to variable in JMeter?

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.
You can do it as follows:
Add Beanshell PostProcessor as a child of the request
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.

How to generate multiple jmeter sampler results from a BSF Sampler?

I have a BSF sampler that runs a groovy script.
I want to create multiple sample results out of this single script in jmeter.
Is it possible?
...my groovy script will run a junit suite and i want to report each junit test separately. Or my groovy script will make 100 http get and i want to display 100 sampler results.
To achieve this you have to organize loop - e.g. put your BSF Sampler under any suitable logic controller: Loop Controller), While Controller, ForEach Controller, or use possibilities of Thread Group (Loop Count, Number of Threads fields).
This scenario will re-use single instance of your BSF Sampler for each new iteration / thread and produce separate sampler result for each execution.
As well you possibly have to provide different entry data / params to BSF Sampler on each iteration - to parametrize it. In this case you can look at least into CSV Dataset Config (to read from file) or any of postprocessors/extractors (go get data from responses).
Suppose you also look into JSR223 Sampler to use along with groovy scripts for better performance.

Resources