如何使用CMDRunner将JTL文件转换为Save table csv?

时间:2018-10-03 08:26:16

标签: java jmeter maven-3 jmeter-plugins

在这里的答案中,建议创建一个bat文件以将JTL文件转换为CSV文件,该文件将具有“保存表数据”。

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

我在项目的CMDRunner.jar文件中添加了pom.xml maven依赖项。使用此代码,我想编写一段Java代码,这将有助于我完成bat文件正在执行的操作。

我不理解此api / jar中提供的功能。我该如何开始?

enter image description here

稍后,我将具有如下所示的Maven生命周期:

  1. mvn clean verify>输出将是jtl文件
  2. MVN测试>使用上面的代码将JTL转换为CSV
  3. mvn sendreports>将csv发送到电子邮件

1 个答案:

答案 0 :(得分:0)

如果您不知道如何使用JMeter插件API,最简单的方法就是使用1,这样您就可以在{{ 3}}

示例 pom.xml 文件如下:

<?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>

它将在 target 文件夹中生成aggregate.csv文件,其中将包含Maven Exec plugin数据的文本表示

对于非Maven执行,您可以使用JMeterPluginsCMD Command Line Tool

安装所需的插件。