JMeter upload file with relative path from the jmx file - jmeter

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

Related

Passing relative path file name in csv config element in 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

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 SMTP Sampler - is it possible to use parameterization with in "attach files" option?

am using JMeter 4.0 and I have been trying to parameterize the filename in "Attach files" option with no success. I am required to use attachments of varying sizes and with each loop a random pdf file (from the set of files saved locally in d drive) to be attached with the email.
I am using a CSV data set config for parameterization and see no issues in using the parameters in Subject line of within the Message.
However, when used with the attach files option, the JMeter test fails to execute with FileNotFoundException as the variable name is substituted as such instead of the pdf filename. Is there a solution?
Error Message: java.io.FileNotFoundException: D:\Data_Jmeter\${AttachFile}.pdf (The system cannot find the file specified)
I cannot reproduce your problem using the following settings:
Where ${path} is set via User Defined Variables on Test Plan level and resolves into "bin" folder of my JMeter installation
The same situation for ${path} variable originating from the CSV Data Set Config
So I would recommend to double check if your ${AttachFile} variable is defined, you can do this using Debug Sampler and View Results Tree listener combination

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

Resources