3
votes

I want to run code at the beginning that sets up variables, but as far as I can tell, the options for running code are:

  1. Sampler: Appears in JMeter reports and screws up my numbers.
  2. Pre-processor/Post-processor/Assertion: Must be attached to existing sampler.
  3. Timer: This works sometimes, but it appears that if you have your timers higher in the tree than your samplers, they just get ignored.
  4. Listener: Runs after your samplers (I want this code to run before everything else).

Is there a way to run code without modifying reports or attaching it to a sampler?

3
It really depends on what you are actually trying to do, so more details would help. One of the most basic things is to use setUp Thread Group, however it won't fit any sort of setup...Kiril S.

3 Answers

4
votes
  1. Add Test Action sampler to the place in the Test Plan where you want to run your code
  2. Add JSR223 PreProcessor as a child of the Test Action sampler
  3. Tick Cache compiled script if available box
  4. Put your code into Script area

This is something you're looking for as

1
votes

See Execution order:

  1. Configuration elements
  2. Pre-Processors
  3. Timers
  4. Sampler ...

For example of Configuration element

The User Defined Variables Configuration element is different. It is processed at the start of a test, no matter where it is placed.

Inside it you can execute JMeter functions which include numerous options as to read from CSV, execute groovy or beanshell code...

1
votes

You can add your action as a Sampler (no matter JSR223 or anything else) and then add a PostProcessor that will mark this Sampler's result as ignored. It can be done with JSR223 PostProcess with groovy script:

prev.setIgnore()

You can also control whether or not to ignore this sample based on the conditions.