在使用硒的黄瓜测试中未发现任何功能异常

时间:2018-08-31 08:40:31

标签: java selenium-webdriver cucumber cucumber-java cucumber-junit

我是黄瓜的新手。当我尝试单独运行功能文件时,没有找到功能异常。我尝试了StackOverflow中已经问到的所有问题的建议,但这些建议对我来说不起作用。请帮助我解决这个问题。

我的功能文件

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

我的跑步者文件

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)

1 个答案:

答案 0 :(得分:0)

做出以下假设

  • 您正在使用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

与您的帖子一样,带有针对Cucumber.class

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

DataTables.feature

与您的帖子一样

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:
...