Fail to Download File Using Jmeter and relative path - jmeter

I'm using JMeter to test concurrent downloads, and need to store it into specific folder.
I'm working on windows and using "Save response to a file". If I use the absolute path it all works exactly as I want it to work.
Now, I need to share this with a group (will be stored in repo) and want to change my obviously wrong absolute path to relative.
Now:
"~" - stores download in project root folder, where .JMX file is, but I want it in: "~/downloads/" so, in subfolder.
None of "regular" things work and yes I tried all possible combinations even those I know it should not work at all.
~/downloads/
./downloads/
~./downloads/
\downloads\
\downloads\
...
It or fails, and I can see in log error like:
~\downloads\1.x-gzip (The system cannot find the path specified)
Or It get's store in root with the filename "downloads" instead 1.x-gzip
Is there a way to do it, maybe using beanshell?
Most important, why is that behavior in JMeter so different, I mean if it works for "home" and "~/../" why it does not recognize subfolders?
Thanks

JMeter seems to be removing trailing slash so there is no way to bypass it apart from providing full path to the folder.
If you need to do it dynamically, relevant Beanshell script will look like:
${__BeanShell(import org.apache.jmeter.services.FileServer;FileServer.getFileServer().getBaseDir() + System.getProperty("file.separator") + "downloads" + System.getProperty("file.separator"),)}
You need to have "downloads" folder at the same level with your .jmx test script.
References:
__Beanshell() - function
FileServer class JavaDoc
How to Use BeanShell: JMeter's Favorite Built-in Component

Related

Get absolute path to directory containing current FreeMarker

In Apache FreeMarker, how can I get the absolute path to the directory containing the current .ftl file?
For example, if I was processing the file /path/to/template.ftl, then I'm searching for a way to get /path/to inside of /path/to/template.ftl.
I've tried .current_template_name and friends, but these really only contain the name of the file, not its absolute path (from which I could get the parent directory). I've also tried absolute_template_name, but this just seems to prepend the name with a / to make the path seem absolute, but it does not resolve to the real absolute path.
Background: I'm templatizing Asciidoc files with with Freemarker, and the Asciidoc files must include other Asciidoc files which reside below the original directory of the .flt file, so they must not be searched relative to the temporarily "expanded" Asciidoc file.
The template paths that templates use are always virtual, and resolved by the TemplateLoader object set in the Configuration. TemplateLoader is just an interface, has multiple implementations, and so is a black box for FreeMarker. The actual location of the template can be inside a jar file, or even in the database table, so in general a template has no path on the file system.
Normally, you set up the TemplateLoader so that it can access all the templates you need. Then you don't need any tricks, and just use template paths.
Another possibility is to use a FileTemplateLoader that uses the root directory as base directory. This of course would be a bad idea for most applications (especially for web applications, for security reasons).

How to provide relative path in Include controller in jmeter for test fragment

I have two thread groups from that in one thread I have two include controllers. but I want to provide relative path instead of absolute path so anyone can use this project in their system. as I am uploading this on GitHub.
enter image description here
If the external .jmx script lives at the same folder - just use its filename like Test Fragment.jmx in the Include Controller
If it resides under a folder - specify its relative location
somefolder/Test Fragment.jmx
For the parent folder:
../somefolder/Test Fragment.jmx
There is includecontroller.prefix property which is being added to the filename specified so if there is a common location for all external JMX files/test fragments you might want to set this property
More information:
Include Controller Documentation
Modularizing for Script Reusability: Examples in JMeter and YAML

delete uploaded file from folder using JMeter

I am sending a HTTP request to upload a file. And the request is setup like this:
uploadFile
And, the Directory Listing plugin pointing to a directory with all files and the request picks one file at a time. It works fine when run with one thread but, when i run in multiple threads, i see that already uploaded file is picked again to upload which leads to error.
I have added regular expression extrator to get the filename from the request body like this:
extract-filename-from-requestbody
And then, I am trying to use a post processor beanshell script to either delete the file from the folder or move to a different folder. But, not been successful. Need some help on this.
The first issue is i am not sure if i am extracting the value the right way. The value is to be got from request body and not request header. But, i dont see that option in the extractor.
Second, i am unable to use/retrieve the value from the extractor. Tried vars.get, vars.getObject and simply "${fileName}". Nothing works.
I don't think that deleting the file will help because Directory Listing Config reads the folder at the beginning of the test (see Execution Order chapter) so no matter whether the file is physically present or not JMeter will try to upload it
If you want to get unique files without repetitions just untick "Rewind on end of list" box:
This way each virtual user will read the next value so there will be no duplicates. When the last file will be used - the test will stop.
More information: Introducing the Directory Listing Config Plugin on JMeter
Also going forward consider using JSR223 Test Elements and Groovy language instead of Beanshell, it's the recommended option since JMeter 3.1

JMeter Scripting: Not getting the dynamic value from response code

I am experienced in HP Loadrunner but new in Jmeter.
I recently recorded a script in Jmeter 3.0 where one of the step is to upload a .pdf file. it is a 2 step process:
Step 1> on the upload window click Browse to locate the pdf file from local drive. Once this is done the server puts the file in a temporary directory in the backend and creates a metadata (dynamic value) for it
FYI: I placed the PDF file in the local folder: "Documents\apache-jmeter-3.0\bin\"
Step 2> Once the local file path has been specified (above step) and the button "Upload File" is clicked the file actually gets uploaded to the server and it gets stored permanently.
At this step I need to provide that dynamic value (metadata) to successfully submit the request.
The problem I am having is Jmeter is not returning the metadata (or dynamic value) on the Step-1 of the upload process-
Screenshot: Request/Response details from Jmeter (Step-1)
I recorded the same steps in Vugen 12.53 and it is returning the dynamic value fine for the Step-1-
Screenshot: Request/Response details from Vugen (Step-1)
Can anyone please help?
Thanks!
I can see LoadRunner and JMeter configuration mismatch when it comes to file upload block, I believe you should amend Files Upload section configuration like:
File Path: full path to your PDF file. If you placed in into JMeter's "bin" folder it may be just PerfTest_file_1.pdf
Parameter Name: this guy is the MOST important and this is where you seem to be having clash. Looking into LoadRunner screenshot you name
"Name=file", "Value=blob\\PerfTest_file_1.pdf", "File=Yes", ENDITEM,
and in JMeter for some reason you set this "Name" bit to "blob". I guess correct setting would be "file":
Other settings seem to be fine.
Going forward in order to avoid such situations you can just record your test scenarios. You need to have files you will be uploading in JMeter's "bin" folder so it could locate it while capturing file upload requests.
References:
HTTP(S) Test Script Recorder
JMeter Proxy Step by Step
Performance Testing: Upload and Download Scenarios with Apache JMeter
Just in case, this is how the request header looks like in JMeter-
Screenshot: JMeter Request Header
SOLUTION:
Simply selecting "Implementation" to either "Java" or "HttpClient3.1" solved the problem.
*Points to be noted:
In the "File Path" field either you need to provide the full path of the file location in local drive ("C:/user/Documents/...PerfTest_file_1.pdf") or place the PDF file in the "bin" folder of the Jmeter application folder and just provide the file name (PerfTest_file_1.pdf) as the path
Parameter value for "File" (in my case "blob") should be same as the "Parameter Name" for the file to be attached*

How to create a variable in env.rb or hook.rb and call in cucumber feature ?

Thank you in advance for help.
I am trying to create variable in env.rb
File_path =("#{File.dirname(__FILE__)}/../../features/TestData/Testdata.html")
and call File_path in the Cucumber feature directly.
for example
...
And I upload a file from path "<File_path>"
...
Is the is a better way of doing this ?
Yes, there's a better way.
In your feature text, use meaningful names instead of file paths.
For example, any of these, depending on your goal:
And I upload a file of test data
And I upload my web page
And I upload some previously saved information
Then put the file path in your step file.
In general, feature descriptions should be plain language, not source code, file paths, env vars, etc

Resources