黄瓜未找到默认步骤定义类

时间:2020-05-08 20:22:06

标签: selenium cucumber

我的黄瓜赛跑者课程似乎找不到我的步骤定义类,但它可以很好地找到特征文件。

这是我非常简单的项目结构的快照:enter image description here

功能文件:

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();
}

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

1 个答案:

答案 0 :(得分: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 {

}