[英]Unable to generate jmeter html report from java code
When trying to generate html report using java code, I can only see a statistics.json generated but no html reports are there.尝试使用 java 代码生成 html 报告时,我只能看到一个统计信息。生成了 json 但没有 ZFC35FDC70D52FC69D26 报告2C7A56。
My Java Code -我的 Java 代码 -
ResultCollector logger = new ResultCollector(summer);
logger.setFilename(csvFile);
testPlanTree.add(testPlanTree.getArray()[0], logger);
//run
StandardJMeterEngine jMeterEngine = new StandardJMeterEngine();
jMeterEngine.configure(testPlanTree);
jMeterEngine.run();
//Report Generator
ReportGenerator rg = new ReportGenerator(csvFile, null);
rg.generate();
In my reportgenerator.properties, I have following entries (only end part)在我的 reportgenerator.properties 中,我有以下条目(仅结束部分)
jmeter.reportgenerator.exporter.html.classname=org.apache.jmeter.report.dashboard.HtmlTemplateExporter
jmeter.reportgenerator.exporter.html.property.template_dir=report-template
jmeter.reportgenerator.exporter.json.classname=org.apache.jmeter.report.dashboard.JsonExporter
jmeter.reportgenerator.exporter.json.property.output_dir=report-output
I have checked that the csv file is generated and has valid data, because i tried generating html report from jmeter command line using the same csv and it worked.我检查了 csv 文件是否已生成并且具有有效数据,因为我尝试使用相同的 Z6328CB5675AAFEZE824 从 jmeter 命令行生成 html 报告,并且它工作了 7AAFEZE824。
After the execution, my java code only produces a statistics.json file but no html reports are generated.执行后,我的 java 代码只生成一个统计信息。json 文件,但没有生成 html 报告。 There are no errors in the logs (only few warnings related to some properties not set and default being used).
日志中没有错误(只有少数与未设置和使用默认属性相关的警告)。
Edit I'm setting the JMeter property jmeter.reportgenerator.outputdir
in java code -编辑我在 java 代码中设置 JMeter 属性
jmeter.reportgenerator.outputdir
-
properties.put(org.apache.jmeter.JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY, "report-path");
The output logs - output 日志 -
Creating statistics for overall
Creating statistics for other transactions
Checking output folder
Writing statistics JSON to path\to\dir\statistics.json
Exporting data using exporter:'html' of
className:'org.apache.jmeter.report.dashboard.HtmlTemplateExporter'
Will generate dashboard in folder: path\to\dir
It says 'will generate dashboard in folder' in the logs but no html is generated.它在日志中显示“将在文件夹中生成仪表板”,但没有生成 html。
Any idea what I might be missing?知道我可能会错过什么吗?
You're missing a very obvious thing: the location of the generated HTML Reporting Dashboard你错过了一个非常明显的事情:生成的HTML 报告仪表板的位置
You need to set jmeter.reportgenerator.outputdir
JMeter Property and provide the full path of the dashboard as the value, to wit before initialization of the ReportGenerator add the next line:您需要设置
jmeter.reportgenerator.outputdir
JMeter 属性并提供仪表板的完整路径作为值,以便在ReportGenerator初始化之前添加下一行:
JMeterUtils.setProperty(org.apache.jmeter.JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY, "/full/path/to/the/dashboard/folder");
More information: Five Ways To Launch a JMeter Test without Using the JMeter GUI更多信息: 在不使用 JMeter GUI 的情况下启动 JMeter 测试的五种方法
After checking out all the configurations, I went on to debug the code in JMeter's ReportGenerator class, to check at what point the code fails.检查完所有配置后,我继续在 JMeter 的 ReportGenerator class 中调试代码,以检查代码在什么时候失败。 Here' the hierarchy of the code used in gnerating html reports -
这里'用于生成 html 报告的代码层次结构 -
ReportGenerator generator = new ReportGenerator(csvFileName, null);
generator.generate();
public void generate() throws GenerationException {
-----
exportData(sampleContext, key, value);
-----
}
private void exportData(SampleContext sampleContext, String exporterName,
ExporterConfiguration exporterConfiguration)
throws GenerationException {
----
exporter.export(sampleContext, testFile, configuration);
----
}
Eventualy, export() method of HTMLTemplateExporter is invoked -最终,调用 HTMLTemplateExporter 的 export() 方法 -
public void export(SampleContext context, File file, ReportGeneratorConfiguration configuration) throws ExportException { ---- Configuration templateCfg = new Configuration( Configuration.getVersion()); ----
The code fails here while creating new configuration for Freemarker.为 Freemarker 创建新配置时,代码在此处失败。 JMeter internally uses Freemarker templating engine to generate the dashboard reports.
JMeter 内部使用 Freemarker 模板引擎来生成仪表板报告。
On further analysis, I could figure out that I had conflicting dependencies for Freemarker library.经过进一步分析,我发现我对 Freemarker 库的依赖项存在冲突。 Freemarker dependencies are added with JMeter lib itslef, while my application was already using a different vesion of freemarker library.
Freemarker 依赖项是通过 JMeter lib itslef 添加的,而我的应用程序已经在使用不同版本的 freemarker 库。 I had to exclude one of the versions (using exclude tags in pom.xml) and made sure that only one version is present.
我必须排除其中一个版本(使用 pom.xml 中的排除标记)并确保只存在一个版本。 (You can check this using maven dependency tree.)
(您可以使用 maven 依赖树进行检查。)
PS - Although in maven dependency tree, initialy it appeared that the older version was omitted and only one version is being used. PS - 虽然在 maven 依赖树中,最初似乎省略了旧版本,只使用了一个版本。 It was the reason I didn't doubt on the library versions conflict.
这就是我不怀疑库版本冲突的原因。 But on debugging, I was convinced that the code was failing due to conflicting libs, and I had to explicitly make sure that only one lib version is there.
但是在调试时,我确信代码由于库冲突而失败,我必须明确确保只有一个库版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.