Тесты на селен и огурец не проводятся в Maven - PullRequest
0 голосов
/ 08 октября 2019

Попытка выполнить мои Selenium/Cucumber тесты через TestNG в Maven с такими командами, как mvn test, mvn install и т. Д., Однако тесты не выполняются

Если я запускаю в RunAs TestNG в моем Eclipse все тесты выполняются нормально.

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, просто вижу, что Build в порядке.

$ 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>

Ответы [ 2 ]

1 голос
/ 08 октября 2019

Добавьте <suiteXmlFiles> config в раздел с надёжным плагином и убедитесь, что testng.xml находится в том же каталоге, что и 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>
1 голос
/ 08 октября 2019

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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...