【问题标题】:Cucumber not finding default step definition class黄瓜找不到默认步骤定义类
【发布时间】:2020-05-08 20:22:06
【问题描述】:

我的黄瓜跑步者类似乎找不到我的步骤定义类,但它找到了功能文件就好了。

这是我非常简单的项目结构的快照:

功能文件:

Feature: Customer must be able to reach the Home Delivery page by clicking the Home Delivery button

Scenario: Test Home Delivery button
    Given PS Restaurants web page is open
    When User clicks on Home Delivery button
    Then Home Delivery page should load

步骤定义类:

package stepDefinitions;

import java.util.concurrent.TimeUnit;

public class E_1_US_1 {
@Given("^PS Restaurants web page is open$")
public void ps_Restaurants_web_page_is_open() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^User clicks on Home Delivery button$")
public void user_clicks_on_Home_Delivery_button() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^Home Delivery page should load$")
public void home_Delivery_page_should_load() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}
}

跑步者类:

package runner;

import org.junit.runner.RunWith;


import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(
        features= {"src/features/Feature_1_1.feature"},
        glue= {"src/stepDefinitions/E_1_US_1.java"}
)
public class Runner {

}

将 Runner 类作为 JUnit 测试运行的输出:

1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.040s


You can implement missing steps with the snippets below:

@Given("^PS Restaurants web page is open$")
public void ps_Restaurants_web_page_is_open() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^User clicks on Home Delivery button$")
public void user_clicks_on_Home_Delivery_button() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^Home Delivery page should load$")
public void home_Delivery_page_should_load() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

我刚刚将输出复制并粘贴到我的步骤定义类中,但它仍然无法识别步骤定义类。之前有人说场景中的每个步骤都没有匹配的胶水代码,但是在我关闭并重新打开功能文件后,这种情况就消失了。

【问题讨论】:

  • 我建议你将你的项目 mavenize,你也可以试试glue= {"stepDefinitions"}
  • 您是否可以尝试执行以下操作:转到您的小黄瓜文件,单击步骤(例如 Given PS 餐厅网页已打开),然后单击 Alt + Enter,然后选择“创建步骤定义” ' 从显示的选项中,选择文件以创建步骤定义并将相应的步骤定义粘贴到那里。每一步都应该这样做。希望对您有所帮助。

标签: selenium cucumber


【解决方案1】:

您可以按如下方式更新您的跑步者课程:

package runner;

import org.junit.runner.RunWith;


import cucumber.api.junit.Cucumber;
import cucumber.api.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(
        features= {"src/features"}, //It will pick all the feature files located in this folder
        glue= {"stepDefinitions"} //Only package name is required here.
)
public class Runner {

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多