在使用 Selenium 的 Cucumber 测试中未发现任何特征异常

Getting No Feature Found Exception in Cucumber Test with Selenium

我是黄瓜新手。当我尝试分别 运行 功能文件时,我没有找到任何功能异常。我尝试了 Whosebug 中已提出问题的所有建议,但这些建议对我不起作用。请帮我解决这个问题。

我的功能文件

Feature: CucumberJava

  Scenario: Logging in to Facebook using DataTables
    Given I have open the "Chrome" browser
    When I open Facebook website
    And Logging in to Facebook using DataTables
      | Feild               | Values              |
      | Email id            | fsferr@dsgs.com     |
      | Password            | dvfsgg              |
    Then Click on Login button

我的 Runner 文件

package cucumberPackage;

import org.junit.runner.RunWith; 
import cucumber.junit.Cucumber; 

@RunWith(Cucumber.class) 
//@Cucumber.Options(format = {"pretty", "html:target/cucumber"}) 
@Cucumber.Options(features="src/test/resources/demo/DataTables.feature",format = {"pretty", "html:target/cucumber"}) 
public class RunnerTest {

}

错误日志

cucumber.runtime.CucumberException: No features found at [src/test/resources/demo/DataTables.feature]
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:47)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:82)
    at cucumber.junit.Cucumber.<init>(Cucumber.java:60)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

做出以下假设

  • 您使用的 Cucumber 版本 <= 1.1.8(因为您使用的是 @Cucumber.Options,已在 1.2.0 版本中删除,当前 Cucumber 版本为 3.0.2,也许认为关于更新到最新版本
  • 当前目录下存在以下文件

    src/test/java/cucumberPackage/RunnerTest.java
    src/test/resources/demo/DataTables.feature
    pom.xml
    

RunnerTest.java

与您的 post 一样,使用 Cucumber.class

的固定导入语句
// import cucumber.junit.Cucumber;
import cucumber.api.junit.Cucumber;

DataTables.feature

如您的 post

pom.xml

<?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>com.suboptimal</groupId>
    <artifactId>cuke-test.so</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <version.cucumber>1.1.8</version.cucumber>
    </properties>
    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>
</project>

运行 mvn test 的测试执行你的场景

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running cucumberPackage.RunnerTest
Feature: CucumberJava

  Scenario: Logging in to Facebook using DataTables # src/test/resources/demo/DataTables.feature:3
    Given I have open the "Chrome" browser
    When I open Facebook website
    And Logging in to Facebook using DataTables
    Then Click on Login button

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.000s


You can implement missing steps with the snippets below:
...