运行 从命令提示符进行黄瓜测试时无法识别步骤定义

Step Definitions are not recognized while running cucumber tests from command prompt

虽然我 运行 来自 IntelliJ IDE 的黄瓜测试,但它运行完美。

然而,当我尝试从命令提示符 运行 创建 运行ner class 后,无法识别步骤定义。

下面是代码的样子:

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

@RunWith(Cucumber.class)
@CucumberOptions(
        glue={"classpath:src\test\java"},
        features = "src\test\resources",
        plugin={"pretty","html:target/site/cucumber-pretty","json:target/cucumber.json"})

public class RunCucumberTests {

}

下面是项目结构的样子。 'LoginSeps' class 包含步骤定义。

报错如下

[错误] 测试 运行:5,失败:0,错误:5,跳过:0,经过的时间:0.79 秒 <<< 失败! - 在 RunCucumberTests [错误] 登录 functionality.Login 成功 已用时间:0.276 秒 <<< 错误! io.cucumber.junit.UndefinedStepException: 步骤 'I am in the login page of application' 和其他 2 个步骤未定义.....

非常感谢任何帮助。

Stepdefiniton classes 应始终位于包中和 src\test\java 文件夹下。

请创建一个包 cucumberStep 或其他东西,然后将 class LoginSteps 移到它下面。

代码:

@CucumberOptions(features = "src\test\resources\features", glue = { "cucumberStep", }, dryRun = false, plugin = { "pretty",
        "html:report/TestReport.html", }, monochrome = true, stepNotifications = true, tags = "@Regression")
 

通过一些重构解决了这个问题。

将步骤定义 class 移至新包并在胶水中引用包名称解决了该问题。

下面是解决方案现在的样子。