簡體   English   中英

在類路徑中找不到任何功能:/cucumberOptions

[英]No features found at classpath:/cucumberOptions

我正在創建一個使用 cucumber、junit 和 TestNG 的自動化項目。 我的POM文件如下:

<?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>main.project</groupId>
  <artifactId>project</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <name>project</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

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

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.141.59</version>
     </dependency>
     <dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
       <version>7.3.0</version>
       <scope>test</scope>
     </dependency>
     <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>5.0.5</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>6.9.0</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
    <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>6.9.0</version>
    </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>6.9.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>6.8.1</version>
        <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
          <configuration>
                  <suiteXmlFiles>
                     <suiteXmlFile>testng.xml</suiteXmlFile>
                 </suiteXmlFiles>
               </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

我還創建了一個新的 cucumberTestNG.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
    <listeners>
        <listener class-name = "project.Listeners"/>
    </listeners>

    <test name="Validate User Login">
      <classes>
        <class name="cucumberOptions.TestRunner"/>
      </classes>
    </test>
   
</suite> 

我的測試跑步者:

package cucumberOptions;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;

//@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features",
        glue = "stepDefinitions")
public class TestRunner extends AbstractTestNGCucumberTests {

}

如果我使用 TestNG Suite 運行 cucumberTestNG 文件,則會收到以下錯誤:

Dec 09, 2020 9:16:16 PM io.cucumber.testng.TestNGCucumberOptionsProvider warnWhenJUnitCucumberOptionsAreUsed
WARNING: Ignoring options provided by io.cucumber.junit.CucumberOptions on cucumberOptions.TestRunner. It is recommend to use separate runner classes for JUnit and TestNG.
Dec 09, 2020 9:16:16 PM io.cucumber.core.runtime.FeaturePathFeatureSupplier get
WARNING: No features found at classpath:/cucumberOptions

文件夾結構:

我的文件結構

我的環境變量中有 Java 和 Maven

I've looked at questions such as cucumber jvm CucumberException: No features found at [] and made sure I have it correct testng with cucumber (first answer) but no luck.

如警告中所述

Dec 09, 2020 9:16:16 PM io.cucumber.testng.TestNGCucumberOptionsProvider warnWhenJUnitCucumberOptionsAreUsed
WARNING: Ignoring options provided by io.cucumber.junit.CucumberOptions on cucumberOptions.TestRunner. It is recommend to use separate runner classes for JUnit and TestNG.

目前您正在導入 junit cucumber 選項。

import io.cucumber.junit.CucumberOptions;

對於 TestNg 跑步者 class 您將需要導入 testng.CucumberOptions

import io.cucumber.testng.CucumberOptions;

來自 cucumber-jvm 存儲庫的示例

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(plugin = { "html:target/results.html", "message:target/results.ndjson" })
public class RunCucumberTest extends AbstractTestNGCucumberTests {

    @DataProvider(parallel = true)
    @Override
    public Object[][] scenarios() {
        return super.scenarios();
    }

}

我遇到了同樣的問題,我通過將 Cucumber 依賴從版本 6.11.0 降級到 1.2.6 解決了這個問題,並且我確保 cucumber-java 和 cucumber-testng 具有與 pom.Z0F635D0E0F3874FFF8B581C132E6C77A 中的 1.2.6 相同的版本可以在下面看到:

在此處輸入圖像描述

Aslo my TestRunner class looks like below instead of extends AbstractTestNGCucumberTests you should( cucumber.api.testng.AbstractTestNGCucumberTests ) 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM