Jmeter根据日期生成JTL和HTML报告
1. 首先格式化日期
echo %DATE%%TIME% set datef=%date:~0,4%%date:~5,2%%date:~8% echo %datef%%timef%
PS: 自己电脑的日期各式一定要是这样的,例如: 2020-10-10, 我电脑之前的系统时间格式是:10/10/2020,这就出现了后面路径拼接的时候出现了问题,大家注意一下
2. 如果文件夹存在就delete掉
rd /s /q "<reportSavePath>\jtl_%datef%" rd /s /q "<reportSavePath>\html_report_%datef%" rd /s /q "<reportSavePath>\Aggregate_report_%datef%"
3. 创建文件夹
md "<reportSavePath>\jtl_%datef%" md "<reportSavePath>\html_report_%datef%" md "<reportSavePath>\Aggregate_report_%datef%"
4. 执行jmeter命令,生成JTL,然后转化成HTML的报告
cd <JMETER_HOME_PATH>\bin
jmeter -n -t <JmeterScriptPath>\JmeterScript.jmx -l <reportSavePath>\jtl_%datef%\jtl_%datef%.jtl -e -o <reportSavePath>\html_report_%datef%
总结完整的脚本(jmeterTest01.bat)如下:
@echo off echo %DATE%%TIME% set datef=%date:~0,4%%date:~5,2%%date:~8% set timef=%time:~0,2%%time:~3,2%%time:~6,2% echo %datef%%timef% rd /s /q "<reportSavePath>\jtl_%datef%" rd /s /q "<reportSavePath>\html_report_%datef%" rd /s /q "<reportSavePath>\Aggregate_report_%datef%" md "<reportSavePath>\jtl_%datef%" md "<reportSavePath>\html_report_%datef%" md "<reportSavePath>\Aggregate_report_%datef%" cd <JMETER_HOME_PATH>\bin jmeter -n -t <JmeterScriptPath>\JmeterScript.jmx -l <reportSavePath>\jtl_%datef%\jtl_%datef%.jtl -e -o <reportSavePath>\html_report_%datef%
PS:具体的系统时间格式化,请看这一篇:https://www.cnblogs.com/irisWhq/p/13793925.html