cucumber jvm CucumberException:在 [] 处找不到功能

问题描述 投票:0回答:11

在我的 cucumber -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 中的“features”选项,它会尝试在与 testrunner.java 相同的目录中查找功能文件

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

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

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

如何让它从那里接收?帮助表示赞赏。

cucumber cucumber-jvm cucumber-junit
11个回答
19
投票

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

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

Maven/Cuke 约定将从 test/java 目录执行测试,并在 test/resources 目录中找到功能文件。我的测试运行程序与你的基本相同,但选项较少:

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

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

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


6
投票

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

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

features = "src/main/resources"

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


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 {}

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”


0
投票

这是一个使用最新 Cucumber 版本的 git 存储库:Cucumber- 示例

克隆此存储库并在本地计算机中运行它。

@Given
已定义并且应该通过。
@Then
@When
应显示为未定义。

它的输出应该是这样的: Output for the Belly feature

使用提到的结构:

src / test / java/ io /cucumber /
{此处步骤定义java并运行cucumber测试文件}
src /test / resources/ io/ cucumber /
{这里是功能文件}

您可以使用

./gradlew clean build
运行 gradle 构建 以及使用
./gradlew clean test --info

的黄瓜测试

如果这有效,请在您的项目中使用相同的格式。


0
投票

只需将 .Feature 更改为 .feature 问题就解决了。

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

一些网上教程已经提到了。F特性带来了这个问题

所以改变外壳就可以解决这个问题


0
投票

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

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


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"})

必须正确设置功能目录


0
投票

cucumber.runtime.CucumberException:在处找不到功能 解决方案: 现在差不多 20 个小时都遇到同样的错误,并浏览了整个互联网,没有找到解决方案,但最终我找到了一些东西,我认为这对每个人都有效。 右键单击您的运行程序文件并选择 runAs,然后单击运行配置,然后转到您的功能文件(如图所示),并在其中配置您的功能路径。然后再跑一次。应该能解决你的问题enter image description here


-4
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.