从Maven执行JMeter插件

10

在使用JMeter插件执行jmeter-maven-plugin时,是否可以使用JMeter插件?

更新

按照Ardesco的有用答案,我尝试将jmeter-plugins依赖项添加到插件定义中,但是我遇到了一堆ClassNotFoundException。看起来Maven在执行JMeter时没有将jmeter-plugin的传递依赖项放入类路径中。有什么想法吗?


请查看答案 https://dev59.com/pWMl5IYBdhLWcg3we3Do#47602584 - UBIK LOAD PACK
3个回答

10

尽管此答案被接受,但仅适用于2.X版本之前。但对于高于2.X版本,请参阅此答案

是的,您可以通过向插件添加依赖项来添加所需的任何库,任何明确定义的依赖项都将复制到您的jmeter/lib目录中。

如果依赖关系是JMeter插件,则可以在配置中指定它,然后该依赖关系将被复制到您的meter/lib/ext目录中:

<plugin>
    <groupId>com.lazerycode.jmeter</groupId>
    <artifactId>jmeter-maven-plugin</artifactId>
    <version>1.9.0</version>
    <executions>
        <execution>
            <id>jmeter-tests</id>
            <phase>verify</phase>
            <goals>
                <goal>jmeter</goal>
            </goals>
            <configuration>
                <jmeterPlugins>
                    <plugin>
                        <groupId>kg.apc</groupId>
                        <artifactId>jmeter-plugins</artifactId>
                    </plugin>
                </jmeterPlugins>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>kg.apc</groupId>
            <artifactId>jmeter-plugins</artifactId>
            <version>1.1.3</version>
        </dependency>
    </dependencies>
</plugin>

这个功能在1.9.0版本之前是不可用的。


谢谢,但这对我不起作用 - 每当它尝试运行测试时,我会收到java.lang.ClassNotFoundException:org.apache.jorphan.util.JMeterException - DeejUK
你需要提交一个错误报告来进行调查。这可能是因为插件当前没有正确加载传递依赖项(需要调查)。解决方法是明确指定传递依赖项。 - Ardesco
谢谢您的回复。我认为问题略有不同,当您回复时,我已经提出了一个插件错误:https://github.com/Ronnie76er/jmeter-maven-plugin/issues/77 - DeejUK
这是否加载了所有插件,包括“jmeter-plugins-webdriver”插件,还是只加载了某个较小的集合? - djangofan
它应该拉取jmeter-plugins jar中的任何内容。 - Ardesco

4
请使用2.6.0或更高版本的插件,并添加以下内容:
<configuration>
    <jmeterExtensions>
         <artifacts>kg.apc:jmeter-plugins-casutg:2.4</artifacts>
    </jmeterExtensions>
    <excludedArtifacts>
        <exclusion>commons-pool2:commons-pool2</exclusion>
        <exclusion>commons-math3:commons-math3</exclusion>
    </excludedArtifacts>
    ...
</configuration>

查看此教程以全面了解使用Maven插件:


0

jmeter 3.4.0

如果您有任何外部依赖项,请使用以下依赖项。

     <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>3.4.0</version>
            <configuration>
                
                <!--testPlanLibraries - if you have any dependency with external jars pls add artifact here-->
                <!-- beanshell preprocessor you can write java so this is useful-->
                <testPlanLibraries>
                     <artifact>com.konghq:unirest-java:3.11.11</artifact>
                 </testPlanLibraries>

                <testFilesDirectory>src/test/jmeter</testFilesDirectory>
                <suppressJMeterOutput>false</suppressJMeterOutput>
                <appendResultsTimestamp>true</appendResultsTimestamp>
                <downloadJMeterDependencies>true</downloadJMeterDependencies>
                <downloadLibraryDependencies>true</downloadLibraryDependencies>
                <downloadExtensionDependencies>true</downloadExtensionDependencies>
                <downloadOptionalDependencies>true</downloadOptionalDependencies>
                <jMeterProcessJVMSettings>
                    <!-- for setting any arguments please use this section -->
                    <arguments>
                        <argument>-Dhttps.use.cached.ssl.context=false</argument>
                        <argument>-Djavax.net.ssl.keyStoreType=jks</argument>
                        <argument>-Djavax.net.ssl.keyStore=${clientCertKeystorePath}</argument>
                        <argument>-Djavax.net.ssl.keyStorePassword=${keyStorePassword}</argument>
                    </arguments>
                </jMeterProcessJVMSettings>
            </configuration>
            <executions>
                <execution>
                    <id>configuration</id>
                    <goals>
                        <goal>configure</goal>
                    </goals>
                </execution>
                <!-- Run JMeter tests -->
                <execution>
                    <id>jmeter-tests</id>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
                <!-- Fail build on errors in test -->
                <execution>
                    <id>jmeter-check-results</id>
                    <goals>
                        <goal>results</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

你可以检查${project-root}/target/long-folder-name/jmeter/lib/,确保你的jar包在那里。对于我来说,我有一个依赖项Urirest,用于进行POST请求以获取令牌。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接