DEV Community

Cover image for How to use CSV file for parameterization in JMeter
Rusydy
Rusydy

Posted on

How to use CSV file for parameterization in JMeter

Parameterization is the process of creating multiple test data sets for a single or multiple users in a test script. This is useful when you want to test the performance of your application with different data sets. For example, you want to test the performance of your application with 100 users, each with a different data set. In this case, you can use parameterization to create 100 users with different data sets.

In this article, we will use Wikipedia as an example. We will test the performance of Wikipedia with 100 users, each with a different search keyword (city names). The search keyword will be read from a CSV file.

The test scenario is as follows: We will conduct a load test on the search functionality of Wikipedia with 100 users, each with a different search keyword (city names). The search keyword will be read from a CSV file. In this scenario, the Jmeter test script will have two HTTP requests. The first request is to open the Wikipedia home page, and the second request is to search for a city name.

Here are the steps to set up this test:

  • Open JMeter and create a new Test Plan.
  • Right-click on the Test Plan and select Add > Threads (Users) > Thread Group. Set the number of threads (users) to 100.

Step 2

  • Right-click on the Thread Group and select Add > Sampler > HTTP Request. Enter the base URL of Wikipedia, which is https://en.wikipedia.org/. Leave the Method as "GET". This request will open the Wikipedia home page.

Step 3

  • Right-click on the Thread Group and select Add > Config Element > CSV Data Set Config. Enter the filename of the CSV file that contains the list of city names. Set the Variable Names to "city".

Step 4

  • Right-click on the Thread Group and select Add > Sampler > HTTP Request. Enter the base URL of Wikipedia, which is https://en.wikipedia.org/. Set the path to "/wiki/" and leave the Method as "GET". In the "Send Parameters With the Request" section, add a parameter with the name "search" and value "${city}". This request will search for the city name on the Wikipedia page.

Step 5

  • Start the test by clicking on the "Start" button. JMeter will now read the data from the CSV file and use it to open the Wikipedia home page and search for the city name for each user. On real-world scenario, we will use non GUI mode to run the test.

To run the test in non-GUI mode, you will need to use the command line. Here are the steps to run the test:

  1. Open a command prompt or terminal window.
  2. Navigate to the directory where JMeter is installed.
  3. Type the following command:

    jmeter -n -t [path to your .jmx file] -l [path to your .jtl file]
    

    For example, if your .jmx file is called "Wikipedia_Performance_Load_Test.jmx" and you want to save the results to a file called "result.jtl", the command would be:

    jmeter -n -t Wikipedia_Performance_Load_Test.jmx -l result.jtl
    
  • You can add other elements, such as listeners, to monitor the performance of the test.

Result 1

Result 2

By using parameterization with a CSV file, you can easily test the performance of your application with different data sets. In this case, we were able to test the search functionality of Wikipedia with 100 users and different city names. This method can be applied to other scenarios as well, such as testing different login credentials or different input fields in a form.

Top comments (0)