【问题标题】:Selenium/Cucumber tests not running in MavenSelenium/Cucumber 测试未在 Maven 中运行
【发布时间】:2019-10-08 11:53:18
【问题描述】:

尝试使用mvn testmvn install 等命令在Maven 中通过TestNG 运行我的Selenium/Cucumber 测试,但是,测试没有运行

如果我在我的Eclipse 中运行RunAs TestNG,则所有测试都会正常执行。

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 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.me.cucumber</groupId>
<artifactId>the-internet-herokuapp</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

   <dependencies>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
    </dependency>


        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.0.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.7.2</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>4.7.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2</version>
    </dependency>

    </dependencies>
    <build>
   <plugins>
      <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
     </build>
 </project>

TESTNG.XML

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >

<suite name="SeleniumSuite">
<test name="testAll">
    <classes>
        <class name="testRunner.junitRunner"/>
    </classes>
</test>
</suite>

然后,当我运行 mvn 命令时,我没有看到 TESTES 块会话,只看到构建就可以了。

$ mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------< br.me.cucumber:the-internet-herokuapp >-------- 
-----
[INFO] Building the-internet-herokuapp 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------- 
-----
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ the-internet- 
herokuapp ---
[INFO] Deleting C:\Users\me\Documents\me\_Github\the- 
internet-herokuapp\the-internet-herokuapp\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ the- 
internet-herokuapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ the- 
internet-herokuapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default- 
testResources) @ the-internet-herokuapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ 
the-internet-herokuapp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to 
C:\Users\me\Documents\me\_Github\the-internet-herokuapp\the- 
internet-herokuapp\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default-test) @ the-internet- 
herokuapp ---
[INFO] ------------------------------------------------------------------- 
-----
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------- 
-----
[INFO] Total time:  3.348 s
[INFO] Finished at: 2019-10-08T13:48:50+02:00
[INFO] ------------------------------------------------------------------- 
---- 
-

下面的人解决了我的问题。这是正确的 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 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.dsanders.cucumber</groupId>
<artifactId>the-internet-herokuapp</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
  <maven.compiler.source>1.7</maven.compiler.source>
  <maven.compiler.target>1.7</maven.compiler.target>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
    </dependency>


        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.6</version>
    </dependency>

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.0.0</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.7.2</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>4.7.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2</version>
    </dependency>

 </dependencies>
 <build>
    <plugins>
        <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
             <version>2.19.1</version>

             <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>

            <dependencies>
                <!--<dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.19.1</version>
                </dependency>-->
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-testng</artifactId>
                    <version>2.19.1</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>

【问题讨论】:

    标签: java maven selenium-webdriver automated-tests testng


    【解决方案1】:

    &lt;suiteXmlFiles&gt; 配置添加到surefire 插件部分,并确保testng.xmlpom.xml 在同一目录中

     <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.22.1</version>
    
                <configuration>
                              <suiteXmlFiles>
                              <suiteXmlFile>TESTNG.XML</suiteXmlFile>
                              </suiteXmlFiles>
    
                </configuration>
      </plugin>
    

    【讨论】:

      【解决方案2】:

      Surefire 通常会自动选择哪个测试框架提供者 根据项目中存在的 TestNG/JUnit 版本使用 类路径。

      参考此链接: https://maven.apache.org/surefire/maven-surefire-plugin/examples/providers.html

      以下是如何将多个提供者指定为依赖项。

      <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.18.1</version>
          <dependencies>
              <dependency>
                  <groupId>org.apache.maven.surefire</groupId>
                  <artifactId>surefire-junit47</artifactId>
                  <version>2.19.1</version>
              </dependency>
              <dependency>
                  <groupId>org.apache.maven.surefire</groupId>
                  <artifactId>surefire-testng</artifactId>
                  <version>2.19.1</version>
              </dependency>
          </dependencies>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-09
        • 1970-01-01
        • 2017-08-08
        • 2019-12-13
        • 2019-08-23
        • 2020-12-27
        • 1970-01-01
        相关资源
        最近更新 更多