Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CSV data set config inside a while loop in JMeter?

I need to test the same set of urls against 5 to 10 servers. URLs are defined in the CSV file. Server names are defined in User Defined Variables config.

I'm using While Controller based on the number of servers to iterate and execute the url requests. My current logic is defined as below:

Thread group
  While controller
   Counter (defines number of servers)
   While controller (inner check "${URL}" != "<EOF>")
     CSV Data Set Config (stop EOF is true)
       HTTP Sampler (with url data)

As per the logic my script will run and read the CSV file once and stop. It's not reading the outer loop. Only inner loop and stopped.

like image 448
user1767083 Avatar asked Oct 26 '12 19:10

user1767083


People also ask

How do I loop a CSV file in JMeter?

you need to set true for Stop thread on EOF in the CSV data Set config, which would stop the loop. JMeter supports CSV files which have a header line defining the column names. To enable this, leave the "Variable Names" field empty. This will automatically fill the corresponding variables with values of the columns.

What is CSV data set config used for in a JMeter test?

The “CSV Data Set Config” enables using CSV files as an external data source, where you can keep unique user data like names, emails and passwords. With the help of this config element, JMeter is able to read the CSV file line by line, and then use split parameters to allocate different values for different threads.

How do you write a while loop in JMeter?

Add the While Controller to your Test Plan. Put the HTTP Request sampler (or any other sampler if you're using a different protocol) under the While Controller. Save the partial or the whole response into a JMeter Variable. It can be done using the Regular Expression Extractor.


1 Answers

Quote from JMeter Manual of CSV Data Set:

By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

Thread groups cannot be nested. So you have to use the threadgroup to iterate in CSV and foreach to iterate in something else. The second option is to generate a CSV with the URL+Server variations, and using simply a single threadgroup to read the CSV.

First option is here.

Iterating URLs outer loop, iterating servers inner loop. You just need a threadgroup and a foreach inside it. See the pictures: User defined variables (servers)enter image description hereenter image description hereenter image description here

Sample results: enter image description hereenter image description hereenter image description here

And of course 3 more results...

You can also play with CSVRead function if you have time :)

like image 180
Gábor Lipták Avatar answered Oct 01 '22 21:10

Gábor Lipták