8

在我的黄瓜 -jvm、Maven、junit 设置中,我的 testRunner 文件为

package com.lebara.testrunner;

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

@RunWith(Cucumber.class)
@Cucumber.Options(

glue = {"com.lebara.stepdefs","com.lebara.framework.main", "com.lebara.testrunner"},
features = "C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources",
format = {"pretty", "html:target/cucumber-html-report", "json-pretty:target/cucumber-report.json"},
tags = {"@UserJourney"}

)
public class RunCukesTest {
}

我在上述目录中有我的功能文件。

如果我运行它,我会得到以下异常:

cucumber.runtime.CucumberException: No features found at [C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources/cucumber]...

如果我删除 testrunner 中的“功能”选项,它会尝试在与我的 testrunner.java 相同的目录中查找功能文件

cucumber.runtime.CucumberException: No features found at [com/lebara/testrunner]

如果我把功能文件放在那里,它就可以工作。

我的问题是为什么没有从我以前的位置提取我的功能文件,我认为这是黄瓜的默认文件结构 - maven 设置。

我如何让它从那里拿起?帮助表示赞赏。

4

10 回答 10

18

您的测试运行程序和功能文件到底在哪里?我有以下完美的设置:

src/test/
    java/
        com/mypackage/
            TestRunner.java
            StepDefinition.java
    resources
        com/mypackage/
            fancy.feature

Maven/Cuke 约定将从 tests/java 目录执行测试,并在 test/resources 目录中找到特性文件。我的测试运行器与您的基本相同,但选项较少:

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

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty"})
public class TestRunner { }

如果您还没有找到答案,希望这会有所帮助。

于 2013-02-11T06:22:22.893 回答
6

我有一个类似于你的设置(不使用 Maven/Cucumber 约定)。在我的选项中,我没有指定从根目录开始的路径,而是从项目的源文件夹中指定功能所在的路径。这是有道理的,否则测试只能在您的机器上运行。

在你的情况下,我认为应该是:

features = "src/main/resources"
于 2013-08-24T16:35:19.560 回答
3
//Removing the space between "**classpath**" and "**:com/**" helped.

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:com/tk/feature/"}, //NOTE: NO SPACE
        glue = {"classpath: com.tk.cucumber"}, 
        plugin = {
                "pretty", 
                "html:build/reports/cucumber" 
                ,"json:build/reports/cucumber-tests/test.json"}
        )
public class RunAPITests {}
于 2020-03-16T16:16:41.007 回答
3

只需添加 features = { "classpath:features/feature.feature"},并且该功能必须在test/resources/features/feature.feature下。

    @CucumberOptions(
        format = {"pretty", "html:target/html"},
        features = {"classpath:features/feature.feature"},
        snippets = SnippetType.CAMELCASE

注意类路径

如果您使用 maven 编译代码时打开target/test-classes/features,您将看到feature.feature

于 2017-01-30T12:08:18.897 回答
0

如果您提供功能文件的完整路径,即

“C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources”在您的查询中,再试一次,用“\\”(双反斜杠)替换“/”字符,如下所示.

"C:\\Users\\sarthak.dayanand\\Documents\\WebRefreshTest\\CukeAutomation\\LebaraWebAutomationTest1\\src\main\\resources\\abc.feature"

于 2014-07-24T07:31:26.660 回答
0

这是一个使用最新黄瓜版本的 git repo:Cucumber- 示例

克隆这个 repo 并在你的本地机器上运行它。已@Given定义,它应该通过。@Thenand@When应该显示为未定义。

它的输出应该是这样的: Belly 功能的输出

使用提到的结构: src / test / java/ io /cucumber /{Step definitions java and run cucumber test files here} src /test / resources/ io/ cucumber /{feature files here}

您可以运行 gradle build using./gradlew clean build 和 cucumber test using./gradlew clean test --info

如果这可行,那么在您的项目中使用相同的格式。

于 2019-08-02T05:56:32.117 回答
0
@RunWith(Cucumber.class)
@CucumberOptions(
    features = {"src/main/resources/cucumber/features"},//your feature path
    tags = "not @Wip",
    glue = {"classpath:steps"},
    plugin = {"pretty", "html:target/cucumber/html"})

您必须正确设置功能目录

于 2022-01-28T09:54:28.340 回答
0

还有另一个发生“未找到功能”错误的实例。我在这个答案下发布了解决方案,因为没有类似的问题。

在 Maven 中设置 Cucumber 项目后第一次尝试运行 Runner 文件时出现此错误。我找到的解决方案如下:转到 Windows 资源管理器中存在“功能”文件的文件夹。检查您尝试运行的功能文件的大小。如果大小为“0”KB,则会显示“未找到功能”错误。对文件进行一些更改,直到显示大于零的值。进行更改后再次运行。

于 2020-09-04T12:29:25.733 回答
0

只需将.F特征更改为.f特征,问题就为我解决了。

还要确保根据您的功能文件夹在CucumberOptions中正确提及功能的路径

网上的一些教程都有提到。带来这个问题的功能

所以改变大小写将解决这个问题

在此处输入图像描述

于 2020-01-27T12:13:30.037 回答
-4

通过将功能文件放在src/test/java下运行程序和步骤文件的位置,或者将其放在src/main/java下,问题将得到解决。

于 2017-04-07T11:29:34.140 回答