Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter upload file with relative path from the jmx file

Tags:

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?

like image 288
Eatdoku Avatar asked May 28 '13 06:05

Eatdoku


People also ask

Which prefix to use to get the relative addressing usage in JMeter?

You can pass JMeter a java property named includecontroller. prefix which can be used to prepend a directory to the JMX file you're including. As per component's reference: Relative file names are resolved with respect to the path of the active test plan.


2 Answers

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

like image 111
PålOliver Avatar answered Oct 13 '22 06:10

PålOliver


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.

like image 21
Farah Avatar answered Oct 13 '22 06:10

Farah