【问题标题】:How to config "pom.xml" to jmeter如何将“pom.xml”配置为 jmeter
【发布时间】:2019-02-21 19:46:06
【问题描述】:

我的 POM.xml 是

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.idea.perf.test</groupId>
    <artifactId>jmeter-perf-tests</artifactId>
    <version>4.1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>jmeter-perf-tests</name>

    <properties>
        <jmeterScriptFile>Jmeter-Gemini-UI-RatePlanReport.jmx</jmeterScriptFile>
        <jmeterThreads>2</jmeterThreads>
        <jmeterRampUpTime>1</jmeterRampUpTime>
        <jmeterLoopCount>1</jmeterLoopCount>
        <Port>443</Port>
        <UrlProtocol>https</UrlProtocol>
        <UrlDomainName>stageg.com</urlDomainName>
        <PropertyList>..\..\..\src\test\properties\GeminiStressboxUI.csv</PropertyList>
        <BinaryDir>..\..\..\src\test\binaries</BinaryDir>
        <jmeterRunScriptFor>RPtHomePage,SelectRCRange,SelectDateRange,SelectMultiPropertyGroups</jmeterRunScriptFor>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.adobe.blazeds</groupId>
                <artifactId>blazeds-common</artifactId>
                <version>3.2.0.3978</version>
            </dependency>
            <dependency>
                <groupId>com.adobe.blazeds</groupId>
                <artifactId>blazeds-core</artifactId>
                <version>3.2.0.3978</version>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>a</artifactId>
                <version>1.2</version>
                <classifier>id</classifier>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>blazemeter</artifactId>
                <version>1.2</version>
                <classifier/>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>a_newAmfProxyConverter</artifactId>
                <version>1.2</version>
                <classifier/>
            </dependency>
            <dependency>
                <groupId>serializeFlex</groupId>
                <artifactId>org.racso.jmeter</artifactId>
                <version>0.0.1</version>
                <classifier/>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>amf_custom_plugin</artifactId>
                <version>1.0</version>
                <classifier>idea</classifier>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>b</artifactId>
                <version>1.2</version>
                <classifier/>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-assets</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/../jmeter/lib/ext</outputDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>JMeter-AMF</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.adobe.blazeds</groupId>
                                    <artifactId>blazeds-common</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.adobe.blazeds</groupId>
                                    <artifactId>blazeds-core</artifactId>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>a</artifactId>
                                    <classifier>idea</classifier>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>a_newAmfProxyConverter</artifactId>
                                    <classifier/>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>blazemeter</artifactId>
                                    <classifier/>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>serializeFlex</groupId>
                                    <artifactId>org.racso.jmeter</artifactId>
                                    <classifier/>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>b</artifactId>
                                    <classifier/>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.apache.jmeter</groupId>
                                    <artifactId>amf_custom_plugin</artifactId>
                                    <classifier>idea</classifier>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Execute JMeter Script-->
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>1.9.0</version>
                <configuration>
                    <suppressJMeterOutput>false</suppressJMeterOutput>
                    <overrideRootLogLevel>debug</overrideRootLogLevel>
                    <jmeterLogLevel>DEBUG</jmeterLogLevel>
                    <testFilesIncluded>
                        <testFilesIncluded>${jmeterScriptFile}</testFilesIncluded>
                    </testFilesIncluded>
                    <jMeterProcessJVMSettings>
                        <xms>4096</xms>
                        <xmx>4096</xmx>
                        <arguments>
                            <argument>-Xprof</argument>
                            <argument>-Xfuture</argument>
                        </arguments>
                    </jMeterProcessJVMSettings>
                    <propertiesUser>
                        <jmeterThreads>${jmeterThreads}</jmeterThreads>
                        <jmeterRampUpTime>${jmeterRampUpTime}</jmeterRampUpTime>
                        <jmeterLoopCount>${jmeterLoopCount}</jmeterLoopCount>
                        <UrlProtocol>${UrlProtocol}</UrlProtocol>
                        <Port>${Port}</Port>
                        <UrlDomainName>${rlDomainName}</UrlDomainName>
                        <PropertyList>${PropertyList}</PropertyList>
                        <BinaryDir>${BinaryDir}</BinaryDir>
                        <jmeterRunScript>${jmeterRunScript}</jmeterRunScript>
                    </propertiesUser>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Execute JMeter Reports-->
            <!--<plugin>-->
                <!--<groupId>com.lazerycode.jmeter</groupId>-->
                <!--<artifactId>jmeter-analysis-maven-plugin</artifactId>-->
                <!--<version>1.0.0</version>-->
                <!--<executions>-->
                    <!--<execution>-->
                        <!--<goals>-->
                            <!--<goal>analyze</goal>-->
                        <!--</goals>-->
                        <!--<phase>post-integration-test</phase>-->
                        <!--<configuration>-->
                            <!--<source>${project.build.directory}/jmeter/results/*</source>-->
                            <!--<targetDirectory>${project.build.directory}/reports</targetDirectory>-->
                            <!--<generateCSVs>true</generateCSVs>-->
                            <!--<generateCharts>true</generateCharts>-->
                        <!--</configuration>-->
                    <!--</execution>-->
                <!--</executions>-->
            <!--</plugin>-->
        </plugins>
    </build>
</project>

您能否建议我应该将这个文件放在哪里以及如何将这个文件中的值读取到 JMeter 中?

例如:

&lt;jmeterThreads&gt;${jmeterThreads}&lt;/jmeterThreads&gt;

我想使用的其他变量是:

<jmeterRampUpTime>${jmeterRampUpTime}</jmeterRampUpTime>
<jmeterLoopCount>${jmeterLoopCount}</jmeterLoopCount>

【问题讨论】:

  • 您使用的是非常旧的 JMeter Maven 插件版本(1.9.0),我建议升级到最新版本(截至撰写本文时为 2.8.6)

标签: jmeter jmeter-maven-plugin


【解决方案1】:

假设您定义了以下块:

<properties>
    <jmeterThreads>1</jmeterThreads>
</properties>

您应该能够将以下部分添加到 JMeter Maven Plugin 声明中:

<configuration>
    <propertiesUser>
        <jmeterThreads>${jmeterThreads}</jmeterThreads>
    </propertiesUser>
</configuration>

并在需要时在 JMeter 测试中使用 __P() function 引用该值:

${__P(jmeterThreads)}

此外,您可以使用 -D 命令行参数修改值,例如:

mvn -DjmeterThreads=100 clean verify

其他属性也应该以同样的方式处理。

参考资料:


完整的 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>org.apache</groupId>
    <artifactId>jmeter-maven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <jmeterThreads>1</jmeterThreads>
    </properties>

    <build>
        <plugins>
            <plugin>
                <configuration>
                    <propertiesUser>
                        <jmeterThreads>${jmeterThreads}</jmeterThreads>
                    </propertiesUser>
                </configuration>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.8.1</version>
                <executions>
                    <!-- 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>
        </plugins>
    </build>

</project>

【讨论】:

    【解决方案2】:

    布局应该是:

    要传递参数,请将 pom.xml 作为 configuration 的子项输入:

        <propertiesJMeter>
             <BUILD_TAG>${project.version}</BUILD_TAG>
             <threads>7</threads>
             <duration>30</duration>
         </propertiesJMeter>
    

    在 jmeter 中,以使用线程为例,您可以使用 __P 函数:

    ${__P(threads,5)

    这个blog解释了整个过程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 2023-02-23
      • 1970-01-01
      相关资源
      最近更新 更多