Passing csv data set config file as parameter to JMeter

12,959

Solution 1

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

Solution 2

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.

Share:
12,959

Related videos on Youtube

betawave92
Author by

betawave92

Updated on September 15, 2022

Comments

  • betawave92
    betawave92 over 1 year

    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.

  • GlorianChris
    GlorianChris about 6 years
    This does not work for reasons specified above by Dimitri T
  • user3581363
    user3581363 over 3 years
    Maybe it is because a while had passed since the answer was published, but after trying out this solution, i can confirm that it does work without any issue, and is more comfortable than Dimitri T's solution, since you dont need to use the "user.params" file or pass an argument.