Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically updating file path for sending files with an HTTP Request in Apache JMeter

I am using Apache JMeter 2.7 to load test Liferay. One such test I am creating involves dynamically generating files and uploading them to Liferay's Document and Media portlet. The problem I'm having has nothing to do with Liferay though... I know this because I can upload a document if I type the exact path into the "file path" box of "Send Files With the Request" in an HTTP request. This is not how I need the test to run.

I want the test to run in such a way that I generate a unique file each loop of the test with a different UUID for the file name (I do so in a BeanShell PreProcessor and it does as I want). I have a user defined variable FILENAME that I use to store the file name. In the HTTP Request, for the file path I use the path C:\Installs\Apache Jmeter\apache-jmeter-2.7\bin\${FILENAME} but JMeter does not process the variable.

When I view the Results Tree, I see the error:

java.io.FileNotFoundException: C:\Installs\Apache Jmeter\apache-jmeter-2.7\bin\${FILENAME} (The system cannot find the file specified)

Yet, if I hard code the file path (for example ...\bin\doc.txt) and use ${FILENAME} as the value for the title of the document(a parameter I send in the HTTP Request), the document(doc.txt) uploads to the portlet with the string value of FILENAME as the title. This lets me know the right string is stored in the variable FILENAME. From this, I deduce that JMeter simply does not replace variables in the file path for sending files in an HTTP Request. If I am incorrect in this conclusion, please let me know how to fix whatever error I have. Has anyone else had this problem?

I am currently trying to create a workaround by adding a BeanShell PreProcessor to this http request that would dynamically update the filepath with the variable name. I would need to set some variable = vars.get("FILENAME"). Anyone know how to proceed from here to set the HTTP file path programmatically? I'm looking in the API for the answer. Any help would be much appreciated because I am completely stumped right now.

like image 822
mistahenry Avatar asked Dec 26 '22 23:12

mistahenry


1 Answers

It is failing because you use \${FILENAME}.
This escapes $ so variable is not interpreted.

Solution:

  • C:\\Installs\\Apache Jmeter\\apache-jmeter-2.7\\bin\\${FILENAME}
    (I cannot test as I am on Mac OS);
  • C:/Installs/Apache Jmeter/apache-jmeter-2.7/bin/${FILENAME}
    (this works on Windows sure).
like image 99
UBIK LOAD PACK Avatar answered Apr 07 '23 23:04

UBIK LOAD PACK