PLATFORM INDEPENDENT JMETER SCRIPT EXECUTION

JMETER SCRIPT EXECUTION Java





In this article, weâll cover how to define the way of platform independent JMeter script execution with the help of jmeter-maven-plugin to make our life easy in Performance testing phase. As technology changes every day, adopting to better solutions will make us SMEs in those areas. 

INTEGRATING JMETER WITH MAVEN

The following points were important:

  1. The plugin avoids the dependency of JMeter installation on the script execution machine. 
  2. It must be possible to start the JMeter test from command line (without gui).
  3. The JMeter GUI should also be accessibla directly via the plugin (e.g. via a separate Maven goal).
  4. Plugin enables the flexibility of configuring the external/custom libs at Runtime.
  5. It must be possible to change and pass the test environment data through command without making any changes at script level 
  6. The plugin should generate meaningful reports (or there must be some other possibility to generate these reports).

Step by Step to integrate Jmeter scripts (*.jmx) with Maven build.

Step 1: Create a maven project and place all the *.jmx files under src/test/jmeter

Step 2: Define the jmeter-maven-plugin in pom.xml file. Below is the sample pom.xml file for reference. 

<?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>com.test.sample</groupId>
<artifactId>sample</artifactId>
<name>sample</name>
 
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>${commons-httpclient-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
 
<profiles>
<profile>
<id>search</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter-maven-plugin-version}</version>
<executions>
<execution>
<id>configuration</id>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
<configuration>
<generateReports>true</generateReports>
<jMeterProcessJVMSettings>
<xms>512</xms>
<xmx>4096</xmx>
</jMeterProcessJVMSettings>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>results</goal>
</goals>
</execution>
<execution>
<id>jmeter-check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
<configuration>
<propertiesUser>
<service.baseUrl>${service.baseUrl}</service.baseUrl>
<service.contextRoot>${service.contextRoot}</service.contextRoot>
<service.protocol>${service.protocol}</service.protocol>
<rampUp>${rampUp}</rampUp>
<numberOfThreads>${numberOfThreads}</numberOfThreads>
<numberOfLoops>${numberOfLoops}</numberOfLoops>
</propertiesUser>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-casutg:2.9</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-basic:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-additional:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-vs:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-dist:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-graphs-ggl:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-webdriver:2.0</artifact>
<artifact>kg.apc:jmeter-plugins-senseuploader:3.0</artifact>
</jmeterExtensions>
<errorRateThresholdInPercent>1</errorRateThresholdInPercent>
<ignoreResultFailures>true</ignoreResultFailures>
<testResultsTimestamp>false</testResultsTimestamp>
<suppressJMeterOutput>false</suppressJMeterOutput>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

jmeter-maven-plugin have multiple sections of goals and configurations in it and each one serves the unique purpose. Lets go in details about each goal and configuration defined.

configure : Generates JMeter configuration requires for script execution.

It do the following actions as part of goal.

  • Configuring JMeter artifacts
  • Copying extensions to jmeter/lib/ext
  • Copying junit libraries to jmeter/lib/junit
  • Copying test plan libraries jmeter/lib
  • Configuring JMeter properties

jmeter : Runs the JMeter tests defined in each *jmx file. We can also define the JVM properties incase of large value of test execution

results : Fails the build on errors in test based on defined error condition . Can be used in different ways based on the need. 

output :

Step 3: The Maven properties can be passed to JMeter via the userProperties option. Inside a JMeter test, you can then access the properties using the function ${__P(propertyName)}. This avoids the change of environment and other common data every time at scripts level and make us to define at runtime. 

*Note: This section is optional can be defined based on project need.

Step 4: Any external libraries used as part of test execution can be defined at jmeterExtensions section which allows users to download the libs from maven or any other custom repo.

Finally we are ready to execute the JMeter scripts by using maven command â¦. Below are few commands for reference

mvn clean verify 
mvn clean verify -Psample -Dservice.baseUrl=www.google.com -Dservice.contextRoot=/search -Dservice.protocol=https -DrampUp=1 -DnumberOfThreads=1 -DnumberOfLoops=1

Final Output:


Comments

Loading…

We use cookies and other technologies to improve your experience on our website and to analyze our traffic. By browsing our website, you consent to our use of cookies and other tracking technologies.

Accept cookies and close this message