Search code examples
csvjmeterbeanshell

How to replace GET path variable from CSV file in JMeter?


I'm trying to replace a variable in the GET path without using any parameter name/value combination as the REST API is using ODATA format.

Example: http://localhost/GetEmployeeData('EMP12345')

In my JMeter script, I have added HTTP Request and set the path like this:

/GetEmployeeData('${empid}')

In my CSV file, I have a single column defined like this:

empid
EMP12345

In CSV Dataset config, I'm pointing to the CSV file and setting the variable name to empid.

What I'm doing wrong?. I get a bad request error and the ${empid} is not getting replaced from the CSV file.

Please help.


Solution

  • We cannot help without seeing your configuration so for the time being I can give you only few pieces of advice:

    1. Check jmeter.log file for any suspicious entries, in the absolute majority of cases you should be able to figure out the failure reason from it
    2. Use full path to the CSV file instead of relative. If it helps - check out where JMeter is looking for the file by the relative path and move it into that folder.
    3. Try replacing the CSV Data Set Config with __StringFromFile() or __CSVRead() functions, the syntax would be:

      • /GetEmployeeData('${__StringFromFile(/path/to/file.csv,,,)}')
      • /GetEmployeeData('${__CSVRead(/path/to/file.csv,0)}')

      Check out Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.


    I cannot reproduce your issue having .csv file in JMeter's "bin" folder and the following CSV Data Set Config setup:

    JMeter CSV Data Set Config

    JMeter Variable substitution