Passing relative path file name in csv config element in jmeter - jmeter

I want to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.
Need resolution to pass relative path file name in csv config element in jmeter.i have used ./filename.csv but the jmeter script doesn't work .I have also used ../filename.csv but jmeter script doesn't work.

Relative to what?
As per CSV Data Set Config documentation:
Relative file names are resolved with respect to the path of the active test plan.
csvdata.txt and ./csvdata.txt - then these are treated as different files
If you have filename.csv in the same directory as your .jmx test plan - just use filename.csv, the ../filename.csv construction will look for the filename.csv file in the parent folder for the active test plan.
If you want to know the full path to the current base directory - look for FileServer entry in the jmeter.log file
INFO o.a.j.s.FileServer: Set new base='/this/would/be/the/base/for/relative/CSV/file/lookup'
you will see where JMeter tries to load the CSV file in the same jmeter.log file

Related

How to read data from csv file in jmeter whose location is not fixed and might change in the future

I have a CSV File whose location is going to change later. Using Jmeter how can I still read the file even if the location change?
You can set the location of the CSV file as a JMeter property and pass it through the command line or through user.properties file
Set the file name with a property in the CSV Data Set Config element
${__P(full-path-to-file,/Users/hansi/Documents/test-data/test-data-users.csv)}
Note: A default value /Users/hansi/Documents/test-data/test-data-users.csv is set in the above screenshot.
2.Define the value
2.1 In user.properties file
full-path-to-file=/Users/hansi/Documents/test-data/test-data-users.csv
or
2.2 Set the property when JMeter test is executed from commandline
./jmeter.sh -n -t test-plan.jmx -Jfull-path-to="/Users/hansi/Documents/test-data/test-data-users.csv"
If the CSV file is going to change location then you could store the test plan which is using the file alongside it. This would maintain the context of the test plan if the CSV itself is going to be moving by storing them together. In JMeter relative file names are resolved with respect to the path of the active test plan (based on the official documentation), allowing you to specify only the name of the file in the CSV Data Set Config Filename property.

Parametrize source folder directory or file path in JMeter

Is there any way to parameterize the CSV data file path or source directory path in JMeter?
There are at least 2 possibilities:
Via User Defined Variables like:
and then referring the variable in the CSV Data Set Config
Or via __P() function like:
the property value can be passed via -J command line argument or put into the user.properties file. See Overriding Properties Via The Command Line for more information.

JMeter: How to specify the users.csv file in the command line

When using JMeter from the command line, I get the following error in my log:
2014/08/05 14:29:43 ERROR - jmeter.config.CSVDataSet: java.io.FileNotFoundException:
/home/stew/YOU_FORGOT_TO_SPECIFY_USERS_CSV_FILE.csv (No such file or directory)
The user.csv file is in the same directory as the testplan.jmx file. Is there an option to specify the file in the command line?
Regards,
Wolf
If you use relative file name for path then it should work, as per reference documentation:
Filename Name of the file to be read. Relative file names are resolved with respect to the path of the active test plan. For distributed testing, the CSV file must be stored on the server host system in the correct relative directory to where the jmeter server is started.
For another solution, Have a look at :
http://jmeter.apache.org/usermanual/functions.html#__P
You use this function in CSV dataset :
${__P(resdir)}
and on command line:
-Jresdir=your path to csv file
I was using Jmeter to test load Moodle and used options -Jresdir and -Jusersfile options to pass usersfile name

JMeter CSV Data for filename

With JMeter files can be sent successfully
Config:
Output (success):
But it doesn't work if changing the file name to a variable.
Attended images you will find file path is set to ${logname}, which can be resolved correctly, but the content-length is incorrect.
After changing the file name to the variable, the http will response error message, saying "java.io.FileNotFoundException: ulog_5b9139cf-5542-42dc-ae76-7fde3a61c67b_235152af-feb7-4249-a168-12ed4abb426c_0.log (The system cannot find the file specified)".
I think the incorrect content-length led to server fail to read the file content. Is is right? How to fix it? Thanks.
Config:
Output (failure):
The filename is resolved correctly, but content length is incorrect:
JMeter is looking for the file in it's Base Dir.
If you look into your jmeter.log file you'll see something like:
2014/03/05 15:52:37 INFO - jmeter.services.FileServer: Default base='/home/jmeter'
2014/03/05 15:52:37 INFO - jmeter.services.FileServer: Set new base='/home/jmeter'
This is where JMeter expects file to be located.
So you can either prefix your ${logname} variable with full path to your user's Desktop like
C:\Users\youruser\Desktop\${logname}
Or alternatively change location where JMeter is looking for files via Beahshell Pre Processor as follows:
import org.apache.jmeter.services.FileServer;
FileServer.getFileServer().setBaseDir("C:/Users/youruser/Desktop");
But use it with caution as it may have impact on other relative paths.

JMeter upload file with relative path from the jmx file

I am creating a HTTP Request Sampler in JMeter to automate uploading file to a http service. Is there a way to set the "File Path" in the "Send Files With the Request" to a relative path from the location of the jmx file?
Yes. (This was confirmed in JMeter v2.9)
You can use the following BeanShell expression in the filename input field:
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}<YOUR FILENAME HERE>
So if your file, "upload.jpg" was located in the same folder as your JMX test file, the complete value would be
${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}upload.jpg
To keep it a bit cleaner, add a "User defined variables" config element where you assign the base of the expression to a variable e.g
SCRIPT_PATH = ${__BeanShell( ...etc
Then your file path input value would read a more readable:
${SCRIPT_PATH}upload.jpg
I'm under version 2.11, and the BeanShell script didn't work for me, to make the CSV file relative, and so to make a relative path you simple need to use this ~/filename.csv. This would mean that the CSV file exist in the same directory as the JMX file. But I guess you can modify it to this for example ~/../results_dir/filename.csv etc..
Good luck.
I found the answer here http://kisbigger.blogspot.com/2013/09/pointing-to-files-with-relative-paths.html which was ...
step 1: Create a user-defined-variable Config element to your
project.
step 2: Add a new variable CONFIG_PATH
step 3: in the value
column place this code : ${__BeanShell(import
org.apache.jmeter.services.FileServer;
FileServer.getFileServer().getBaseDir();)}
step 4 : use the variable
name wherever you want like ${CONFIG_PATH}\config.xml
having a filename.csv in the same folder as the jmx and putting ~/filename.csv with JMeter 2.11 and a newer JAVA did not work

Resources