0
votes

Hi i am trying to execute Jmeter Junit sampler having maven dependencies.

I have included all selenium jars into the lib folder along with the standalone server. Also , my pom.xml looks as follows:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MySeleniumLoadTest</groupId>
<artifactId>MySeleniumLoadTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <!-- <version>4.0.0-alpha-5</version> -->
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>compile</scope>    <!-- our scope is not test but compile -->
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.8.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <type>maven-plugin</type>
    </dependency>
    <dependency>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>3.1.1</version>
        <type>maven-plugin</type>
    </dependency>
</dependencies>

  <build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.8.5</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>org.sonatype.haven.HavenCli</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
    <!-- Generate JMeter configuration -->
    <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>
org.eclipse.m2e lifecycle-mapping 1.0.0 com.lazerycode.jmeter jmeter-maven-plugin [3.1.1,) configure

Whenever i import the following jar file into the lib/junit folder, and execute the junit sampler, the code does not get executed on selecting Junit 4 and the class name. Also there is no error shown in view results tree. I am attaching my jar file. Could you please point out what mistake i am making?

1

1 Answers

1
votes

You will see the error in the View Results Tree listener only if sampler can be executed, if it cannot be executed due to improper JMeter configuration - you should be looking for error messages in jmeter.log file

Also the way you're adding dependencies is not suitable for JMeter Maven Plugin, it uses Eclipse Aether which has different dependencies resolution logic

So you need to change your pom.xml file to look like:

<?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.example</groupId>
    <artifactId>jmeter-maven</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <!-- Generate JMeter configuration -->
                    <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>
                <configuration>
                    <testPlanLibraries>
                        <artifact>org.seleniumhq.selenium:selenium-java:3.141.59</artifact>
                        <artifact>com.amazonaws:aws-lambda-java-core:1.2.0</artifact>
                        <artifact>org.testng:testng:6.4.13</artifact>
                        <artifact>io.github.bonigarcia:webdrivermanager:3.8.1</artifact>
                    </testPlanLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Once done you should put the .jar containing only your test code to the "lib/junit" folder of your JMeter installation

More information: