0

In an answer here it is suggested to create a bat file to convert JTL file into CSV file which will have "save table data."

Jmeter command line to "save table data" in a aggregate report

I have added CMDRunner.jar maven dependency in project's pom.xml file. Using this I want to write a piece of java code that would help me to do what bat file is doing above.

I don't understand the functions given in this api/jar. How do I start?

enter image description here

Later I would have maven life cycle which would run as follows:

  1. mvn clean verify > Output will be jtl file
  2. mvn test > JTL converted to CSV using piece of code from above
  3. mvn sendreports > send csv to email
paul
  • 4,333
  • 16
  • 71
  • 144

1 Answers1

0

If you don't know how to use JMeter Plugins API the easiest way would be going for Maven Exec plugin, this way you will be able to execute JMeterPluginsCMD Command Line Tool with necessary parameters in arbitrary phase of Maven Build Lifecycle

Example pom.xml file would look like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jmeter-maven</groupId>
    <artifactId>com.example.jmeter-maven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.7.0</version>
                <configuration>
                    <jmeterExtensions>
                        <artifact>kg.apc:jmeter-plugins-cmd:2.1</artifact>
                        <artifact>kg.apc:cmdrunner:2.2.1</artifact>
                        <artifact>kg.apc:jmeter-plugins-cmn-jmeter:0.6</artifact>
                        <artifact>kg.apc:jmeter-plugins-graphs-basic:2.0</artifact>
                        <artifact>kg.apc:jmeter-plugins-synthesis:2.1</artifact>
                        <artifact>kg.apc:jmeter-plugins-filterresults:2.1</artifact>
                    </jmeterExtensions>
                    <downloadExtensionDependencies>false</downloadExtensionDependencies>
                </configuration>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>copy-cmdrunner-to-lib-folder</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <basedir>${basedir}/target/jmeter/lib/ext</basedir>
                            <executable>cp</executable>
                            <commandlineArgs>cmdrunner-2.2.1.jar ..</commandlineArgs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>generate-aggregate-report</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <basedir>${basedir}/target/jmeter/lib</basedir>
                            <executable>java</executable>
                            <commandlineArgs>-jar cmdrunner-2.2.1.jar --tool Reporter --generate-csv ${basedir}/target/aggregate.csv --input-jtl ${basedir}/target/jmeter/results/${timestamp}-test.csv --plugin-type AggregateReport</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

It will produce aggregate.csv file in target folder which will contain textual representation of the Aggregate Report data

For non-Maven executions you can install the required plugins using JMeter Plugins Manager

Dmitri T
  • 159,985
  • 5
  • 83
  • 133