Home > Software engineering >  How to iterate a request dynamically for each user in JMeter
How to iterate a request dynamically for each user in JMeter

Time:10-29

I need to iterate a request multiple times in JMeter for different users. The iteration number differs for each users. For example: I need to iterate a request 5 times for first user, 3 times for second user and only 1 time for 3rd user and so on. How can we do this and how the input can be fed to the same. Is it possible to say read first 5 line for first user and next 3 lines for second user in csv data set config.

CodePudding user response:

Here is a solution for your problem. There could be many other solutions available in JMeter.

You can define the loop count associated with the users (threads) in a (User Parameters)enter image description here

This panel allows you to specify a series of values for any User Variable. For each thread, the variable will be assigned one of the values from the series in sequence. If there are more threads than values, the values get re-used.

Then the requests can be placed within a enter image description here

The User Parameters component shall be placed within a JSR223 Sampler to ensure the values are initiated before the loop controller is reached. Also the enter image description here

Test plan structure

enter image description here

CSV Data Set Config more suitable for large numbers of parameters

CodePudding user response:

  1. You can define the desired loops count for each user in the CSV file or via JMeter Properties

  2. You can read the desired line from the CSV file using __groovy() function like:

    • ${__groovy(new File('test.csv').readLines().get(0),)} - read 1st line
    • ${__groovy(new File('test.csv').readLines().get(1),)} - read 2nd line
    • etc.
  • Related