JMeter Parameter Setting – Unique Each Occurrence

JMeter is a freeware tool which is in high demand. But lack of some features restricts JMeter to become a powerful tool. One of them is not getting some important features directly like Parameter Setting which is easily available in LoadRunner (Refer to LoadRunner Parameter Settings). As this feature is not directly available in JMeter, so you need to make use of some of the existing elements in the JMeter and implement the mode of accessing the parameter value as required. For this purpose, you would require 4 elements to add under Thread Group:

  1. Loop Controller
  2. Counter
  3. CSV Data Set Config
  4. BeanShell Sampler

The Parameter file i.e. CSV file has the following values:

Figure 01: CSV File with Parameter Value

Add all the above-mentioned elements under a thread group (Refer to Figure 02)

JMeter Parameter Setting - Unique Each Occurrence 02
Figure 02

Click ‘Loop Controller’ and provide the value in ‘Loop Count’ field which should be equal to the number of occurrences. In this example, I have taken 3 as loop count i.e. I want to use 3 values from the list within the same iteration. Refers to Figure 03.

JMeter Parameter Setting - Unique Each Occurrence 03
Figure 03

Let’s have a look at the CSV Data Set Config and apply the same in your scenario. Make sure you provide the correct CSV file path and variable name.

JMeter Parameter Setting - Unique Each Occurrence 04
Figure 04

The ‘Counter’ element is used to generate a new variable each time in which parameter value will be substituted in the sampler request (Pay attention to number format as in a similar way it has to be substituted in sampler request)

JMeter Parameter Setting - Unique Each Occurrence 05
Figure 05

Now, write the given code the BeanShell Sampler. This code will read the value from the CSV file and assign it to the variable name generated by the counter.

JMeter Parameter Setting - Unique Each Occurrence 06
Figure 06

So, here we have completed the set-up to generate the unique value at each occurrence of the parameter.

Now, come to the sampler request part where we will use these variables. To illustrate the scenario, I have used a dummy sampler. Let’s consider below is my original request.

Figure 07

Now, I will modify the request as per the setup to pass the different values from the parameter list at each occurrence.

Figure 08

Now, run the test and see the result in the ‘View Result Tree’ listener.

Figure 09
Figure 10

Important Notes:

  1. Make sure you have sufficient test data to simulate the ‘Unique Each Occurrence’ scenario.
  2. ‘Recycling of Test Data’ and ‘Stop Thread when test data is exhausted’ settings can be controlled by the CSV Data Set Config element setting. Use those settings wisely.

You may be interested:

6 thoughts on “JMeter Parameter Setting – Unique Each Occurrence”

  1. Hi Can you please attach sample jmter file or may be github link for this example. So that would be much helpfull.
    Thanks,
    Prasad

  2. Hi Prasad,

    even you can simulate the scenario by following the screenshots. This is a pretty simple scenario of JMeter.

  3. it will work for multiple users?? to pick five values for each user at a time, for ten users
    please help me bro in this scenario…
    thanks
    Sai

Comments are closed.