5
votes

I would like to be able to pass a CSV file containing parameters for a JMeter test (CSV Data Set Config) to use instead of having the CSV Data Source hard coded as part of the JMeter test. Is this possible? I cannot seem to find this anywhere / in the list of command-line options for JMeter.

Reference for JMeter Data Set Config.

2

2 Answers

11
votes

It is possible, but don't use JMeter Variables as a part of CSV Filename as they are being initialized after CSV Data Set Config so you'll get "file not found" errors. Go for JMeter Properties instead.

  1. In CSV Data Set Config instead of hard-coded filename use JMeter property reference via __P() or __property() function like:

    • ${__P(csvfile,)}
    • ${__property(csvfile,,)}

      CSV File Property Name

  2. Aforementioned csvfile property which pointing to the CSV file path can be defined in 2 ways:

    • in user.properties file (lives in JMeter's "bin" folder) like:

      csvfile=/path/to/your/file.csv
      
    • via -J command-line argument like

      jmeter -Jcsvfile=/path/to/file.csv -n -t test.jmx -l results.jtl
      

    Property value specified via command-line will override the one which is stored in the file. See Apache JMeter Properties Customization Guide for more information regarding JMeter properties and ways of working with them

2
votes

If you are looking to manipulate the file you pass to the Jmeter via a variable, you need to create a user defined variable and then map that variable in CSV Dataset Config. In the following example, I am passing a csv file that can be controlled at runtime via the parameter cids

Step 1: Define user defined variables. In my case, I am using three different csv files.

enter image description here

Step 2: call these variables as file names in each csv dataset config.

enter image description here

Now, you have a jmx, the inputs to which can be controlled by the user defined variables. This is pretty convenient when you schedule jobs via maven or similar ones.