首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法运行包含maven的selenium-junit项目。

无法运行包含maven的selenium-junit项目。
EN

Stack Overflow用户
提问于 2020-07-06 12:44:45
回答 1查看 124关注 0票数 0

嗨,我正在尝试执行具有maven依赖项的J抄Junit采样器。

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

代码语言:javascript
复制
<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>
代码语言:javascript
复制
                                                                  org.eclipse.m2e                 lifecycle-mapping                 1.0.0                                                                                                                                                                                                           com.lazerycode.jmeter                                                                                                                   jmeter-maven-plugin                                                                                                                   [3.1.1,)                                                                                                                   configure                                                                                                                                                                                                                                                                                                             

每当我将以下jar文件导入lib/junit文件夹并执行junit示例时,只要选择Junit 4和类名,代码就不会执行。此外,视图结果树中没有显示错误。我正在附加我的罐子文件。你能指出我犯了什么错误吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-06 15:47:29

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

另外,添加依赖项的方式不适合JMeter Maven插件,它使用的是具有不同依赖分解逻辑日食醚

因此,您需要更改您的pom.xml文件如下:

代码语言:javascript
复制
<?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“文件夹中。

更多信息:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62756382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档