在我的 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 设置的默认文件结构。
如何让它从那里接收?帮助表示赞赏。
您的测试运行程序和功能文件到底在哪里?我有以下设置,效果完美:
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 { }
如果您还没有找到答案,希望这对您有所帮助。
我有一个与你类似的设置(不使用 Maven/Cucumber 约定)。在我的选项中,我没有指定从根目录开始的路径,而是从保存功能的项目源文件夹指定路径。这是有道理的,因为否则测试只能从您的机器上运行。
就你的情况,我认为应该是:
features = "src/main/resources"
只需添加 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
//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 {}
如果您提供功能文件的完整路径,即
“C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources”如您的查询中所示,通过用“\”(双反斜杠)替换“/”字符重试,如下所示.
“C:\ Users \ sarthak.dayanand \ Documents \ WebRefreshTest \ CukeAutomation \ LebaraWebAutomationTest1 \ src \ main \ resources \ abc.feature”
这是一个使用最新 Cucumber 版本的 git 存储库:Cucumber- 示例
克隆此存储库并在本地计算机中运行它。
@Given
已定义并且应该通过。 @Then
和 @When
应显示为未定义。
使用提到的结构:
src / test / java/ io /cucumber /
{此处步骤定义java并运行cucumber测试文件}
src /test / resources/ io/ cucumber /
{这里是功能文件}
您可以使用
./gradlew clean build
运行 gradle 构建
以及使用 ./gradlew clean test --info
的黄瓜测试
如果这有效,请在您的项目中使用相同的格式。
还有另一个例子,出现“未找到功能”错误。我在此答案下发布解决方案,因为没有类似的问题。
在 Maven 中设置 Cucumber 项目后第一次尝试运行 Runner 文件时出现此错误。我找到的解决方案如下:转到 Windows 资源管理器中包含“feature”文件的文件夹。检查您尝试运行的功能文件的大小。如果大小为“0”KB,则会显示“未找到功能”错误。对文件进行一些更改,直到显示大于零的值。更改后再次运行。
@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"})
必须正确设置功能目录
将功能文件放在 src/test/java 下,其中运行程序和步骤文件或 通过将其放在 src/main/java 下,问题将得到解决。