Writing to a file named with variables in distributed JMeter testing - jmeter

Okay I've been having an issue with writing results to folders in JMeter.
I have set 2 variables, one for the name of the test and one for the submit date. I want the reports to be written to the folder named with these two variables.
Here's the variables:
TestRun = "Name of test"
DateRun = $__{time(dd-MMM-yyyy HH.mm.ss)}
The path of the folder to be written to looks like this:
C:\Tests\TestEnvironment\Results\\${TestRun}${DateRun}\file.csv
When I run it on the master machine, it's fine. It saves to the correct file and folder path, and ends up looking something like this:
C:\Tests\TestEnvironment\Results\Test Run 1 - 08-May-2014 08.55.47\file.csv
However, when I run it on remote machines, it saves it literally as below:
C:\Tests\TestEnvironment\Results\${TestRun}${DateRun}\file.csv
So I end up with a folder named "${TestRun}${DateRun}"
Am I missing something blindingly obvious, or is this an actual JMeter issue?
Thanks!

As per JMeter help:
-G, --globalproperty <argument>=<value>
Define Global properties (sent to servers)
e.g. -Gport=123
or -Gglobal.properties
You need to use -G key so your variables could be distributed across remote clients.
so something like:
jmeter -r -n GTestRun=SomeName -GDateRun=SomeTime -t /path/to/your/plan
should help.
Alternatively you can create a .properties file and pass it to remote JMeter Engines via the same "-G" option.
I expect that if you want to use JMeter __time() function you'll need to wrap it with __eval, elsewise it will be treated as a string. Alternatively you can use operating system commands to retrieve current date and time.
See Apache JMeter Properties Customization Guide for more information on dealing with JMeter Properties.

Related

Variable in library path with JMeter is not working

My JMeter plan config looks like this:
as you can see from the picture the mypath variable has a default value /somehwere which may change based on the machine that hosts JMeter.
So I added it as variable in the ${mypath}/bin below for Library.
However if I run a command like:
jmeter -n ... -Jmypath=/newpath/elsewhere
it is not working. Is there any way to put that path as variable?
You need to amend the variable using __P() function like:
${__P(mypath,/somepath)}
This way you will be able to override the value using -J command-line argument and if you don't provide the override value it will default to /somepath
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
Overriding Properties Via The Command Line
I answer myself as the solution required is using the parameter -Juser.classpath=some_path which avoid the need to create an external parameter for that case.

Using time function in Summary Report listener filename

In JMeter (5.1.1) I have a summary report that I'm trying to save as a timestamped file. The filename value looks like the following:
D:\Load Tests\example.com\Results\${__time(yyyy-MM-dd-HH-mm-ss,)}_summary.csv
However, rather than create the file with the result of the __time() function e.g. 2019-07-22-10-24-03_summary.csv, it's actually generating a filename called ${__time(yyyy-MM-dd-HH-mm-ss,)}_summary.csv.
I've tried creating a user-defined variable called timestamp with the value ${__time(yyyy-MM-dd-HH-mm-ss,)} and referencing it with ...\${timestamp}_summary.csv but this similarly results in $(timestamp)_summary.csv.
I saw a JMeter Archive post regarding a similar question to mine from 2006 where it's implied that listener filenames are resolved too early for functions and variables to be used, but I'm hoping that JMeter has been able to overcome this hurdle in the 13 years since then.
Is it possible to use variables for listener filenames in JMeter GUI and set them dynamically like the timestamp above?
If not, is there an alternative method of doing this using Groovy? Where would this be - in a setup thread JR223 sampler perhaps? I have tried this and seemingly managed to programatically change the filename, but no file was saved.
Update with answer:
I just needed to reverse the path delimiters from \ to /.
D:/Load Tests/example.com/Results/${__time(yyyy-MM-dd-HH-mm-ss,)}/summary.csv
I come across this issue and figure out that it works when you specify your path with the slash, instead of backlash.
For example:
D:\Load
Tests\example.com\Results\${__time(yyyy-MM-dd-HH-mm-ss,)}_summary.csv
Doesn't work. But:
./Load
Tests/example.com/Result/${__time(yyyy-MM-dd-HH-mm-ss,)}_summary.csv
Will work.
I usually don't write long answers, but you touch a bit of a sore point,
Listeners are classic example of Can't Live with You, Can't Live Without You
JMeter mindset is load testing (although can be used for functional tests)
Therefore, the moto/best practice is You shouldn't use it
Use CLI mode: jmeter -n -t test.jmx -l test.jtl
Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
Don't use "View Results Tree" or "View Results in Table" listeners during the load test, use them only during scripting phase to debug your scripts.
But...in the same document it suggest it for testing/debugging
Create a simple Test Plan containing the JSR223 Sampler and Tree View Listener. Code the script in the sampler script pane, and test it by running the test.
Basically/In the end, you need to save first jtl file using -l myresults.jtl
And then convert it to CSV using JMeterPluginsCMD, example:
JMeterPluginsCMD.bat --generate-csv test.csv --input-jtl results.jtl --plugin-type ResponseTimesOverTime
Or do it the JMeter way with creating a dashboard
jmeter -g <log file> -o <Path to output folder>
You should not be using any Listeners in your tests as it violates JMeter Best Practices
Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
you should be running JMeter in non-GUI mode like:
jmeter -n -t test.jmx -l summary.jtl
If you want to amend the summary.jtl filename to include timestamp - you can use date and time commands combination like:
jmeter -n -t test.jmx -l %date:~-4%-%date:~4,2%-%date:~7,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%_summary.jtl
Demo:

JMeter parametrization $URL

I have problem with set parametrize $url variable in Jmeter.
I must set parametrize because I will run my project test in three other URL addresses, because application is deployed for 3 others such as production, development and I also would like testing in local.
I have the following CSV file:
protocol
$url
${dev} http://10.200.XXX.XX/{$url}
${trial} trial.mycompany.io{$url}
${product} product.mycompany.io{$url}
How can I set this in JMeter, set parametrization my URL variable?
Your question is not very clear, moreover my expectation is that you shouldn't have JMeter variables reference in form of ${variable} in the CSV file, only "plain" data should go there.
With regards to running test on different servers I would go for creating 3 separate CSV files, i.e.
dev.csv with the following contents:
protocol,host
http,10.200.XXX.XX/
trial.csv with the following contents
protocol,host
https,trial.mycompany.io
product.csv with the following contents
protocol,host
https,product.mycompany.io
Once done you can add a CSV Data Set Config and set it up like:
And finally add HTTP Request Defaults to your Test Plan to read the values from the relevant CSV file:
So when you run JMeter without any parameters it will pick up dev.csv file and will go to 10.200.XXX.XX host
If you run JMeter like:
jmeter -Jenvironment=trial
it will pick up trial.csv and will go to trial.mycompany.io host
If you run JMeter like:
jmeter -Jenvironment=product
it will pick up product.csv and will go to product.mycompany.io. host
More information:
__P() function
Overriding Properties Via The Command Line

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 global properties and Simple Data Writers

I am setting a Jmeter global property on the command line with the -G option. I try to use this property to alter the file name of a Simple Data Writer. However, In the data writer the __P function returns only the default.
jmeter -t ... --nongui ... -GFileName=MyFile.xml ...
So, I know that I am setting the global property correctly. Both the jmeter log and the Jmeter server log show that the value is being captured from the command line. However it still refuses write a file name with anything other than the default.
I use the following command
filename_${__P(FileName,Default.fl)}
How do I pass in a value at the command line so that I can use it as the file name for a Simple Data Writer?
Notes: I am using remote servers, so I must use -G, and I already have a primary data file output, so I cannot use -l .
Why not to use -J or -D directives to set your property?
Everything will work as you want in case of
-JFileName=MyFile.xml
or
-DFileName=MyFile.xml
In both the cases you can than further refer to this property in Simple Data Writer as ${__P(FileName,)}.
Well, I've got the same negative result as your while trying to use global (-G) property but I cannot find in your situation described any prerequisites to use global (-G) properties instead of local (-J) or system (-D) ones.
Global properties are defined to be sent to remote servers... are you executing test in client-server mode (jmeter-server started)?
Than, as per 18.3.9 Simple Data Writer
When running in non-GUI mode, the -l flag can be used to create a data file.
I.e. running
jmeter -n -t ... -l MyFile.xml
will give you the same result in MyFile.xml.
As additional note.
You can try to use JMeterPlugins solutions:
Flexible File Writer - instead of native Simple Data Writer.

Resources