JMeter has an element that allows you use external data sets in a CSV format that is called “CSV Data Set Config” element. It is used to read lines from a file, and split them into variables.  

The following article elaborates in the detail on the how to use this element in JMeter.

If you already know how to use it in JMeter but wish to run your tests in BlazeMeter, please refer to this article which will elaborate on that procedure.

First I will create a test-plan. It contains one Thread Group. A Thread group consists of “HTTP Request Defaults”, “CSV Data Set Config” and “HTTP Request”. Also, I will add “Aggregate Report” and “View Results Tree”. See Figure 1.

CSV Data Set Config
Figure 1

I guess that if you read this article, there is no sense in explaining how to use “HTTP Request Defaults”, “HTTP Request”. Also, I hope you already know that “Aggregate Report” and “View Results Tree” are used for gathering results. Look at the Figure 2.

CSV Data Set Config fields
Figure 2

You’ll need to fill in at least 3 values on this screen:

  • Filename: if your file is in the /bin directory, this can be just the filename. If it’s somewhere else, use the full path to the file.
  • Variable names: this is the equivalent to a “column name” in a spreadsheet.
  • Delimiter: comma is the default delimiter, but if your file uses tabs, this is the place to say so.

The other fields are optional but they may be useful to you. Read all about them on the JMeter CSV Data Set Config user manual.

I have 4 variables for passing to Login request. They are “user”,”passwrd”,”cookielength”,”cookieneverexp”. And, look at the Figure 3 to see what I have in csv_data.txt.

How to fill csv_data.txt
Figure 3

Let’s switch to Login request, Figure 4.

HTTP Post request
Figure 4

You see the table with variables. There are 4 variables, the same quantity as in 'CSV Data Set Config', but the 4th variable is invisible due to JMeter issue. As you can notice, the value field has the same name as variable in 'csv data set'. Construction ${….} means that is variable, but not absolute value.

Now, if I run the test-plan, JMeter will parse 'csv_data.txt' and change ${passwd}, ${user}, etc., with their values. Results are displayed on Figure 5.

HTTP Post request results
Figure 5

It is worth mentioning that every 'CSV Data Set Config' is visible to all Thread Groups by default. If you need to use separate 'CSV Data Set Config' element for every Thread, you have to create a number of data files that you need, and in 'CSV Data Set Config' element set it from “Sharing mode” to “Current Thread”



Want to learn more? You'll want to view our on-demand recording, How to Create Advanced Load Testing Scenarios with JMeter

Have more questions? Submit a request


Article is closed for comments.