3 minutes read

Apache JMeter is a Java-based, open source testing tool, which can help you create and run functional and load tests for Websites, APIs (REST and SOAP) and other web services.

In this example we are going to have a look on how to create and run a JMeter test using a CSV file for our data, and consume the data in our test from that CSV file.

First, let’s open JMeter and create a new JMeter test script.

Add a Thread Group

Inside the Thread Group add the following:


CSV Data Set Config


HTTP Request

View Results Tree

Configure the CSV Data Set Config

Why do we need a CSV Data Set Config config element?

Because the CSV Data Set Config is used to read lines from a file, and split them into variables, and is exactly what we need to be able to generate this data-driven tests.

Inside the CSV Data Set Config there are few fields you need to configure in order to run Apache JMeter tests and load the data for the test from a CSV file.

The Filename is the property which defines the name of the file to be read and we can use relative paths with respect to the JMX test script.

So to use a CSV file located in the same folder as the JMX file, simply add ./ in front of the CSV filename: ./file1.csv

In order to use the values extracted from the CSV file, we need to define the variable names, in our case is a list of users and passwords, so we’ll add user,password (names must be separated by the delimiter character).

Note: JMeter supports CSV header lines: if the variable name field empty, then the first line of the file is read and interpreted as the list of column names.

Next step is to choose the delimiter, we found out that the easiest to use is the comma delimiter, so in our CSV file we’ll separate the key,value pairs with a comma as below:

John1,password1

John2,password2

John3,password3

More details on the CSV Data Set Config can be found in the JMeter docs.

Configure the HTTP Request

Now, in the HTTP Request Sampler we are going to use the values extracted from the CSV file by appending the variable names at the end of the PATH for the GET request:

https://example.com?${user}&${password}

We are going to run the JMeter test script we’ve created and check in the View Results Tree listener that the values for the PATH field in each request are going to be updated with the values extracted from the CSV file used in the CSV Data Set Config.

And we can see that the GET requests made have the following Paths:

GET https://example.com?John1&password1

GET https://example.com?John2&password2

GET https://example.com?John3&password3

Run JMeter Tests with CSV Data Files in the Cloud

Now that we have a JMeter JMX test script and a CSV file used by the JMX file to inject the data in the test, we can run this test in the cloud from multiple cloud locations with thousands of virtual concurrent users using the JMeter Cloud Load Testing Tool.

Just go to New JMeter Test page, and upload the JMX and CSV files and hit the Run Test button, and your test will automatically run in the cloud:

START TESTING TODAY


Written by Bogdan Vazzolla.

LoadFocus is a cloud testing platform, a load and stress testing tool which provides the infrastructure to run tests with thousands of concurrent users, from multiple cloud locations, in less than a few minutes, keep history of the results, compare different runs to inspect performance improvements or performance degradation. It also supports running JMeter load tests from the cloud and monitoring and audit web and mobile performance.

How fast is your website? Free Website Speed Test