Cucumber没有运行我的步骤定义文件(java)

Cucumber没有运行我的步骤定义文件(java),java,selenium,junit,cucumber,Java,Selenium,Junit,Cucumber,当我运行我的测试运行程序时,cucumber会生成一个缺少的步骤,尽管我已经在Test_steps类中实现了这些步骤。我能够使用eclipse中的“查找步骤”从功能文件导航到Test_步骤类。请帮忙。非常感谢 黄瓜商: @RunWith(Cucumber.class) @CucumberOptions( format = { "pretty","html: cucumber-html-reports", "json: cucumber-html-report

当我运行我的测试运行程序时,cucumber会生成一个缺少的步骤,尽管我已经在Test_steps类中实现了这些步骤。我能够使用eclipse中的“查找步骤”从功能文件导航到Test_步骤类。请帮忙。非常感谢

黄瓜商:

@RunWith(Cucumber.class)
@CucumberOptions(
    format = { "pretty","html: cucumber-html-reports",
               "json: cucumber-html-reports/cucumber.json" },
    features = {"src/features"},
    glue ={"src/features"}
)

public class CucumberRunner {

}
第一,特色:

Feature: Login Action

  Scenario: Successful Login with Valid Credentials    
    Given User opened STM
    When User in LogIn Page
   Then Message displayed Login Successfully
测试步骤(步骤定义文件):

文件夹结构:所有包都在src文件夹下

功能文件:/src/features/first.feature 步骤定义文件:/src/features/Test\u Steps.java

控制台输出:

Feature: Login Action

  Scenario: Successful Login with Valid Credentials [90m# first.feature:3[0m
    [33mGiven [0m[33mUser opened STM[0m
    [33mWhen [0m[33mUser in LogIn Page[0m
    [33mThen [0m[33mMessage displayed Login Successfully[0m

1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s
您可以使用以下代码段实现缺少的步骤:

@Given("^User opened STM$")
public void User_opened_STM() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@When("^User in LogIn Page$")
public void User_in_LogIn_Page() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@Then("^Message displayed Login Successfully$")
public void Message_displayed_Login_Successfully() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}
@CucumberOptions#glue
属性(我承认文档记录得很差)应该指向您的步骤所在的包。否则,Cucumber将在与
CucumberRunner
类相同的包中查找步骤

话虽如此,有两点意见:

  • 确保您的类位于命名包中,而不是“默认”文件包中。未命名的包。只是为了让事情变得容易些
  • 运行
    CucumberRunner

您能显示您的目录结构吗?运行“CucumberRunner”时的控制台输出?更新了我问题中的控制台输出
@Given("^User opened STM$")
public void User_opened_STM() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@When("^User in LogIn Page$")
public void User_in_LogIn_Page() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

@Then("^Message displayed Login Successfully$")
public void Message_displayed_Login_Successfully() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}