3

I have a user defined variable that I put the location to a csv file.

csv_path = mydrive/thisfolder/thecsv.csv

When I put ${csv_path} as my filename argument in the CSV Data Set Config element I get an error and it shows up that the path is only the name of the csv file. If I manually put the filename in there it works. Any ideas? I am trying to create a relative path to it rather than hardcoding an absolute path.

2 Answers 2

5

When you define the user defined variables, assign the path of the csv file (relative paths work) using a property like shown below:

enter image description here

And then, in your CSV Data Set Config, refer that file using the property name like this:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

4

CSV Data Set Config element is initialized before any JMeter Variables so consider using a JMeter Property instead. JMeter Properties is an instance of java.util.Properties hence inherit all the features like:

  • Properties are global for the JVM and once defined live until JVM is shut down
  • As a consequence of previous point - you can use JMeter Properties to share data across Thread Groups while JMeter Variables are local to their own Thread Group and cannot be accessed outside
  • You can specify a default value so i.e. if property is not overrided - the reasonable default is being used instead

So in order to parametrize your CSV file name:

  1. Define a JMeter property. There are 2 main ways:

    • Add the following line to user.properties file (lives in JMeter's "bin" folder)

      csv_path = mydrive/thisfolder/thecsv.csv
      
    • Pass the property to JMeter via -J command-line argument like:

      jmeter -Jcsv_path = mydrive/thisfolder/thecsv.csv -n -t ....
      

      See Apache JMeter Properties Customization Guide for more information on different JMeter and Java properties types and ways of working with them

  2. Once you defined the property you can access it's value where required using __P() or __property() function like:

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

It's better to develop functions using Functions Helper Dialog as their syntax might seem scary.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.