硒/黄瓜测试未在Maven中运行 [英] Selenium/Cucumber tests not running in Maven

查看:83
本文介绍了硒/黄瓜测试未在Maven中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to run my Selenium/Cucumber tests through TestNG in Maven with commands like mvn test, mvn install, etc. however, the tests are not running

如果我在EclipseRunAs TestNG中运行,则所有测试都将正常执行.

If I run in RunAs TestNG in my Eclipse, all tests are executed normally.

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

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块会话,只是看到Build正常.

Then when I run the mvn commands I am not seeing the TESTES block session, just seeing the Build is ok.

$ 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

THE GUYS BELOW SOLVED MY PROBLEM. HERE ARE THE CORRECT 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>

推荐答案

<suiteXmlFiles>配置添加到surefire插件部分,并确保testng.xmlpom.xml位于同一目录中

Add <suiteXmlFiles> config to surefire plugin section and make sure testng.xml is in the same directory as pom.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>

这篇关于硒/黄瓜测试未在Maven中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆