Atul Kumar
Atul Kumar

Reputation: 73

how to generate jmeter dashboard report through maven project

I am able to generate Jmeter dashboard report manually using this command jmeter -g /path/to/jtl/file -o /where/you/want/to/store/dashboard but I want to generate it through maven project.

Is there any way?

Below is the plugin ex:

<goals>
<goal>jmeter</goal>
</goals>
<configuration>
    <propertiesUser>
    <jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
    <jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
    <jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
    <jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
    <jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
    <jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
    <jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
    <jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
    <jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
    <jmeter.save.saveservice.time>true</jmeter.save.saveservice.time></propertiesUser>
<propertiesSaveService>
    <output_format>csv</output_format>
</propertiesSaveService>

Upvotes: 1

Views: 2512

Answers (2)

vins
vins

Reputation: 15400

This is how I create the HTML report with mvn using mvn ant plugin.

I have my report-template and reportgenerator.properties under src/testresources.

    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>2.0.3</version>
            <configuration>
                <testResultsTimestamp>false</testResultsTimestamp>
                <propertiesUser>
                    <jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
                    <jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
                    <jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
                    <jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
                    <jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
                    <jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
                    <jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
                    <jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
                    <jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
                    <jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>
                </propertiesUser>
            </configuration>
            <executions>
                <execution>
                    <id>jmeter-tests</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <configuration>
                        <tasks>
                            <mkdir dir="${basedir}/target/jmeter/results/dashboard" />
                            <copy file="${basedir}/src/test/resources/reportgenerator.properties" 
                                  tofile="${basedir}/target/jmeter/bin/reportgenerator.properties" />
                            <copy todir="${basedir}/target/jmeter/bin/report-template">
                                <fileset dir="${basedir}/src/test/resources/report-template" />
                            </copy>
                            <java jar="${basedir}/target/jmeter/bin/ApacheJMeter-3.0.jar" fork="true">
                                <arg value="-g" />
                                <arg value="${basedir}/target/jmeter/results/*.jtl" />
                                <arg value="-o" />
                                <arg value="${basedir}/target/jmeter/results/dashboard/" />
                            </java>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168197

First of all you will need to configure JMeter Maven Plugin to store the test results in the format, suitable for HTML Reporting dashboard generation, i.e. add the next few lines to your pom.xml file:

<jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
<jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
<jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
<jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
<jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
<jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
<jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
<jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
<jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
<jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>

I believe the most straightforward way would be using Exec Maven Plugin, something like:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>verify</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-jar</argument>
            <argument>${basedir}/target/jmeter/bin/ApacheJMeter-3.0.jar</argument>
            <argument>-g</argument>
            <argument>${basedir}/target/jmeter/results/${maven.build.timestamp}-example.jtl</argument>
            <argument>-o</argument>
            <argument>${basedir}/target/dashboard</argument>
        </arguments>
    </configuration>
</plugin>

You might need to copy reportgenerator.properties file and report-template folder to "target/jmeter/bin" directory of your Maven project (it will not survive "clean" phase) or duplicate the properties as it described in Adding Additional Properties To chapter.

See Five Ways To Launch a JMeter Test without Using the JMeter GUI article for more information on different options of executing a JMeter test

Upvotes: 0

Related Questions