shashi009
shashi009

Reputation: 760

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.

My Java Code -

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)

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.

After the execution, my java code only produces a statistics.json file but no html reports are generated. 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 -

properties.put(org.apache.jmeter.JMeter.JMETER_REPORT_OUTPUT_DIR_PROPERTY, "report-path");


The output logs -

   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.
Any idea what I might be missing?

Upvotes: 1

Views: 2143

Answers (2)

shashi009
shashi009

Reputation: 760

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. Here' the hierarchy of the code used in gnerating html reports -

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 -

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. JMeter internally uses Freemarker templating engine to generate the dashboard reports.

On further analysis, I could figure out that I had conflicting dependencies for Freemarker library. Freemarker dependencies are added with JMeter lib itslef, while my application was already using a different vesion of freemarker library. I had to exclude one of the versions (using exclude tags in pom.xml) and made sure that only one version is present. (You can check this using maven dependency tree.)

PS - Although in maven dependency tree, initialy it appeared that the older version was omitted and only one version is being used. 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.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 167992

You're missing a very obvious thing: the location of the generated HTML Reporting Dashboard

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:

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

Upvotes: 2

Related Questions