【问题标题】:cucumber jvm CucumberException: No features found at []cucumber jvm CucumberException:在 [] 处未找到任何功能
【发布时间】:2022-01-28 17:54:28
【问题描述】:

在我的黄瓜 -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 设置。

如何让它从那里取走?帮助表示赞赏。

【问题讨论】:

    标签: cucumber cucumber-jvm cucumber-junit


    【解决方案1】:

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

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

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

    【讨论】:

    • 从“.features”更改为“.feature”为我修复了它;谢谢
    【解决方案2】:

    我的设置与您的类似(不使用 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

      【讨论】:

        【解决方案4】:
        //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 {}
        

        【讨论】:

          【解决方案5】:

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

          "C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources" 在您的查询中,通过将 '/' 字符替换为 '\\' 重试(双反斜杠) 如下。

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

          【讨论】:

            【解决方案6】:

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

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

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

            使用提到的结构: src / test / java/ io /cucumber / {步骤定义 java 并在此处运行黄瓜测试文件} src /test / resources/ io/ cucumber / {这里有功能文件}

            您可以使用 ./gradlew clean build 运行 gradle 构建 以及使用./gradlew clean test --info的黄瓜测试

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

            【讨论】:

              【解决方案7】:

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

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

              网上的一些教程都提到了。F带来这个问题的特征

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

              【讨论】:

                【解决方案8】:

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

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

                【讨论】:

                • 我有同样的错误,特征文件大小为非零。
                【解决方案9】:
                @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"})
                

                必须正确设置功能目录

                【讨论】:

                  【解决方案10】:

                  将功能文件放在 src/test/java 下,其中 runner 和 steps 文件或 把它放在 src/main/java 下,问题就会得到解决。

                  【讨论】:

                  • 不要将测试代码放在 src/main 下。该文件夹通常包含投入生产的代码,而您不希望将测试代码投入生产。
                  猜你喜欢
                  • 2013-12-26
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-10-18
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-10-16
                  • 1970-01-01
                  相关资源
                  最近更新 更多