Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run JSR223 PreProcessor only once

Tags:

jmeter

I have a test plan in jMeter that requires some parameters that needs to be calculated before running the test. In order to calculate these parameters, I created a JSR223 PreProcessor directly under test plan as seen below.

Test Plan

My problem is PreProcessor seems to run before every request which is not what I want. I need to calculate these parameters only once and use them in testing.

Is there a way to run the JSR223 PreProcessor only once, or should I use another method?

Thanks in advance.

Edit:

As @ubik-load-pack suggested, I tried "setUp Thread Group" as following but variables created in the code was not available under "Thread Group". They were also present neither in the logs (logging is used in the code) nor in the View Results Tree (via Debug PostProcessor)

enter image description here

I also tried "Once Only Controller" which also didn't work, same as above.

enter image description here

For more information here is content of my JSR223 PreProcessor. (Not the whole code, there will be more variables here so using date functions is not a solution for me by the way.)

enter image description here

like image 233
Birkan Cilingir Avatar asked Jul 08 '15 06:07

Birkan Cilingir


People also ask

What is JSR223 PreProcessor in JMeter?

The JSR223 PreProcessor is another way of scripting by using PreProcessors. JSR223 has similar functionality to the BeanShell preprocessor. The main difference from BeanShell is that you can use additional scripting languages: ecmascript, groovy, java, javascript, jexl and nashorn.


1 Answers

By design a PreProcessor runs before any Sampler runs.

So if you want to run something only once per user, you can do the following:

  • Use a Once Only Controller and put in it a JSR223 Sampler that will contain your code.

If you want to do it once for all users, then use a setupThreadGroup that will contain your JSR223 Sampler and configure it with 1 thread. It will run once before the regular Thread Groups are started.

EDIT after you updated your question:

  • As I wrote, you cannot use the setupThreadGroup approach if you want to reuse variables in Thread Groups so stick to OnceOnlyController approach for your request

  • With the Once Only Controller it is not working because you misread my answer, I am suggesting to use a JSR223 Sampler not PreProcessor as a preprocessor will run only if there is a sampler that runs.

like image 92
UBIK LOAD PACK Avatar answered Nov 01 '22 11:11

UBIK LOAD PACK