【问题标题】:Unable to run a selenium-junit project having maven in jmeter无法在 jmeter 中运行具有 maven 的 selenium-junit 项目
【发布时间】:2020-07-06 12:44:45
【问题描述】:

您好,我正在尝试执行具有 maven 依赖项的 Jmeter Junit 采样器。

我已将所有 selenium jar 与独立服务器一起包含到 lib 文件夹中。 另外,我的 pom.xml 如下所示:

<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 生命周期映射 1.0.0 com.lazerycode.jmeter jmeter-maven-插件 [3.1.1,) 配置

每当我将以下 jar 文件导入 lib/junit 文件夹并执行 junit 采样器时,选择 Junit 4 和类名时代码不会执行。视图结果树中也没有显示错误。我附上了我的jar 文件。你能指出我犯了什么错误吗?

【问题讨论】:

    标签: maven selenium-webdriver junit jmeter


    【解决方案1】:

    只有当采样器可以执行时,您才会在查看结果树侦听器中看到错误,如果由于不正确的 JMeter 配置而无法执行 - 您应该在 jmeter.log file 中查找错误消息

    此外,您添加依赖项的方式不适合 JMeter Maven 插件,它使用 Eclipse Aetherdependencies resolution logic 不同

    所以你需要改变你的 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.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>
    

    完成后,您应该将包含仅测试代码的 .jar 放入 JMeter 安装的“lib/junit”文件夹中

    更多信息:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 2020-09-21
      • 1970-01-01
      相关资源
      最近更新 更多