When creating load testing projects, we usually integrate JMeter with Apache Ant to run JMeter scripts in a batch. The test result auto-generated by JMeter ONLY provides the data collected during the load testing run. To present a comprehensive test report, visualizing such data to charts or diagrams are required. One of the solutions for such a visualization is hereby proposed: Transforming default JMeter results to HTML-format files by using Ant script. Personalized test reports can then be created based on these HTML files.
Details of this solution are as follows:
Precondition:
- Install and configure Ant.
- Install and configure JMeter.
- Make sure you can use Ant to run JMeter scripts in batch. (copy JMeter/extras/ant-JMeter-1.1.1.jar into Ant/lib)
Step 1, Change result format to xml (default is cvs):
In JMeter.properties, modify the core, change output format to xml as the following:
jmeter.save.saveservice.output_format=xml (Default is cvs.)
Step 2, Use Ant to run JMeter scripts.
Add the core in build.xml, they may look like the following:
<target name=”test”>
<taskdef name=”jmeter” classname=”org.programmerplanet.ant.taskdefs.jmeter.JMeterTask” />
<jmeter jmeterhome=”${jmeter.home}” resultlog=”${jmeter.result.jtlName}”>
<property name=”jmeter.save.saveservice.output_format” value=”xml”/>
<testplans dir=”${basedir}\ScriptsToRun” includes=”*.jmx” />
</jmeter>
</target>
After running the scripts, a JTL file is generated automatically.
Step 3, Transform .jtl to HTML.
Add a target in build.xml to generate an HTML report. The core may look like the following:
<target name=”report”>
<xslt in=”${jmeter.result.jtlName}” out=”${jmeter.result.htmlName}”
style=”${jmeter.home}/extras/jmeter-results-detail-report_21.xsl” />
//use a xsl template named jmeter-results-detail-report_21.xsl to parse jtl //report and generate HTML.
<copy todir=”${jmeter.result.html.dir}”>
<fileset dir=”${jmeter.home}/extras”>
<include name=”collapse.png” />
<include name=”expand.png” />
</fileset>
</copy>
</target>
Step 4, Run build.xml with Ant.
You will be able to find the HTML and .jtl files in the folder which you assigned.
.jtl:
HTML:
The HTML may looks like this:
The workflow of how to generate an HTML report based on the original JMeter results is presented in the following chart:
As indicated by the above chart, if we code an xsl template to parse the .jtl (.xml format) report, then we can use ant to generate our own HTML report.
JMeter provides some xsl templates in its subfolders. I use one of the templates in the example, and found some problems:
i) The Date Report is undefined.
ii) The Max/Min time is NaN.
iii) The HTML’s style does NOT look comfortable.
These problems can be fixed by doing the following:
Step 1. Use Ant to pass the parameter to xsl.
Open the xsl template, a parameter named dateReport can be found.
Use Ant to pass a parameter.
Step 2. Add a path in the build.xml
Xalan*.jar and serializer*.jar are required to parse .xml, then convert it to HTML.
As “Max/Min” can be found in the .jtl Report, this problem is probably caused by missing of a jar.
Step 3. Run build .xml with Ant.
The following is a proper report after the xsl template style is modified.