JMeter CSV Dataset Config: how to move through variables in the same thread?

Ashkan Aryan picture Ashkan Aryan · Sep 6, 2011 · Viewed 31.6k times · Source

I'm using a CSV dataset config element, which is reading from a file like this:

abd
sds
ase
sdd
ssd
cvv

Which, basically, has a number of 3 letter random string.

I'm assigning them to a variable called ${random_3}.

Now, I want to use values from this list multiple times within the same thread, but each time I want to move to next. For example, I want the first sampler to use abd, the 2nd to use sds, then ase, etc. But if I just use ${random_3} then only the first one (abd) is used wherever it's referred to. Is there a way I can specify to loop through the values from the CSV dataset within a thread?

Answer

TechTrip picture TechTrip · Jan 27, 2012

CSV Data Set Config works fine for this. All of the values need to be in one column in the file and assign them to the variable as described.

Create a Thread Group that has as many threads for as many users as you want iterating over the file (i.e. acting on the HTTP Request). Assuming 1 user, set the number of threads to 1, loop count to 1.

Inside the thread group you will need to add a Loop Controller or a While Controller. You indicated that you want to loop through the whole data set. If you add a loop controller you will want to set the Loop Count to 6, since you have 6 values, one for each value. Alternately (and easier for processing the whole file) add a While Controller instead of a Loop Controller and set ${random_3} as the while condition.

It is important to set the CSV Data Set Recycle on EOF and Stop Thread on EOF values correctly. If you plan to iterate over the file more than once you must set "Recycle on EOF" to True (i.e. instruct jMeter to move back to the top of the CSV file). Set "Stop Thread on EOF" to False if you are using a loop controller, true if you are using a while controller and want to stop after reading the whole csv dataset.

Add the CSV Data Set Config as a child of the controller along with the HTTP Request. View the results using any listener you want to use.