how to generate jmeter dashboard report through maven project - jmeter

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>

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>

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

Related

How to create a folder if not exist in Maven?

I am writing pom.xml newly and i am trying to Delete a folder already existing and create a new folder.Is there a way to do this? I am looking something like this:
<executions>
<execution>
<configuration>
<tasks>
<if><!-- I need to check if the folder exists and delete->
<delete>
<fileset dir="target/resources"/>
</delete>
</if>
<mkdir dir="target/resources"/>
</tasks>
</configuration>
</execution>
using maven antrun plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<configuration>
<target>
<mkdir dir="${project.build.directory}/target/resources" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Another option would be to use exec-plugin

maven wsdl2java configuration not working properly

I am looking to execute wsdl2java via maven and have tried several different methods with no full success. The first way I was doing it:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.apache.axis.wsdl.WSDL2Java</mainClass>
<arguments>
<argument>-client</argument>
<argument>-o</argument>
<argument>gensrc</argument>
<argument>wsdl/JobAPIWebWrapped.wsdl</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
This version will create the exact structure that I am looking for due to the call to org.apache.axis.wsdl.WSDL2Java, but will not continue with any other maven plugins beyond that. It ends the log with executing main or something to that effect.
The other method I have tried:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>gensrc</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>wsdl/JobAPIWebWrapped.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with this execution is that it generates a lot more java files than the previous execution stated higher up. I have checked the compatibility of this larger fileset and found it will work fine, but would like to find a way to force it to execute with the same java class as the first example. This version will, however, complete and allow me to move on to the following plugins called by maven.
Third:
<plugin>
<groupId>org.apache.axis</groupId>
<artifactId>wsdl2java-maven-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<implementationClassName>org.apache.axis.wsdl.WSDL2Java</implementationClassName>
</configuration>
</execution>
</executions>
</plugin>
This version isn't even being recognized... wondering if I am calling the plugin incorrectly because it isn't even showing up anywhere with verbose logging.
I have been searching quite a bit and have yet to find a successful answer. I am very close to just writing a shell script to run the maven set-up by calling the first example then moving on. Any help is greatly appreciated. Thanks.
Instead of using the exec-maven-plugin invoking WSDL2Java, you should use axistools-maven-plugin. Your pom would look like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<wsdlFiles>
<wsdlFiles>wsdl/JobAPIWebWrapped.wsdl</wsdlFiles>
</wsdlFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
By the way, Apache Axis is quite old and broken. You should think about moving to Apache CXF which is more recent and more robust.
I gave in and ended up using the antrun plugin for maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<java classname="org.apache.axis.wsdl.WSDL2Java" fork="true">
<arg value="-client"/>
<arg value="-o"/>
<arg value="gensrc"/>
<arg value="wsdl/JobAPIWebWrapped.wsdl"/>
<classpath refid="maven.compile.classpath"/>
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

what is the equivalent of "ant -f" command in maven?

I have an xml file called MakeJar.xml in the location ${basedir}/codebase.
On my shell if I have to run that file i used to use the command "ant -f MakeJar.xml".
Now if I have to run this file using pom.xml how can I do that?
I prepared a following pom.xml. But it dosent work!!!
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile="${basedir}/codebase/MakeJar.xml"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Looking at the ant task definition the attribute antfile is described as "the buildfile to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given."
So you probably have to use:
<ant dir="${project.basedir}" antfile="codebase/MakeJar.xml" />
Also do not forget to specify a <phase> in the plugin section (is missing in your code). The following definition works for me:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<ant
dir="${project.basedir}"
antfile="codebase/MakeJar.xml" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Copy a jar file with maven

I'm trying to copy the .jar, created by Maven 3, to another location.
Currently, I'm using Ant's copy task, but Maven simply doesn't copy the file.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Maven and Exec: forking a process?

I'm trying to use Maven to start an application prior to running some integration tests on it. I'm on Windows. My Maven plugin configuration looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-my-application</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>start_application.bat</executable>
<workingDirectory>./path/to/application</workingDirectory>
</configuration>
</execution>
<executions>
<plugin>
and my batch file looks like this:
start myApplication.exe
When run in isolation, the batch file spawns a separate window to run the application and immediately returns control.
However, when run from Maven, the build waits for the process in the separate window to finish before continuing. This somewhat defeats the point of the integration testing phase...
Any ideas how I can start a truly separate process in Maven to allow the build to continue alongside it?
For the record, a rather hackish solution is to use maven-antrun-plugin to call Ant, which is capable of spawning separate processes:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<target>
<exec executable="cmd"
dir="./path/to/application"
spawn="true">
<arg value="/c"/>
<arg value="start_application.bat"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Try this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-my-application</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>call</executable>
<arguments>
<argument>start_application.bat</argument>
</arguments>
<workingDirectory>./path/to/application</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>

Resources