Using time function in Summary Report listener filename

孤街浪徒 提交于 2020-03-23 14:09:30

问题


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.


回答1:


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>



回答2:


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.




回答3:


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:



来源:https://stackoverflow.com/questions/57143194/using-time-function-in-summary-report-listener-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!