Search code examples
javamavenjmeterjmeter-pluginsjmeter-maven-plugin

How to run take the users defined variables of Jmeter from command line when running the test through jmeter-maven plugin


I build a test plan on Jmeter and running that from maven. But I don't know how to take those user defined variables from the command line when I am running the test on maven that I have specified in Jmeter. For example I have defined the number of threads field in jmeter with "${__P(users)}", or I have some if controller condition to run the specific thread. And specified the if condition of if controller with "${__P(tiff)}" == "true".

So

  • how do I take the values of tiff or users from command line when I am running the test with maven. What should I include in my POM.xml file?
  • how should I write the command line statement to achieve this goal

My dependencies and plugins in pom.xml are as follows:

<dependencies>
    <dependency>
      <groupId>org.jvnet.hudson.plugins</groupId>
      <artifactId>jmeter</artifactId>
      <version>0.3.0</version>
      <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>1.9.1</version>
            <executions>
                <execution>
                    <id>jmeter-tests</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Solution

  • First add this block after description tag

     <properties>
         <test.users>30</test.users>
          <test.tiff>true</test.tiff>
      </properties>
    

    Add after executions tag this block:

                <configuration>                       
                    <propertiesUser> 
                        <users>${test.users}</users>
                        <tiff>${test.tiff}</tiff>
                    </propertiesUser> 
                </configuration> 
    

    Then run;

     mvn -Dtest.users=50 -Dtest.tiff=true verify