使用java获取cucumber中未定义的场景和步骤

使用java获取cucumber中未定义的场景和步骤,java,selenium,junit,cucumber,Java,Selenium,Junit,Cucumber,我已经和这件事斗争了两天了。我的测试显示已通过,但测试未在cucumber+java for Selenium webdriver测试中运行。在控制台中,我收到以下消息 1 Scenarios (1 undefined) 4 Steps (4 undefined) 0m0.000s You can implement missing steps with the snippets below: @Given("^User navigate to shopping page$") publi

我已经和这件事斗争了两天了。我的测试显示已通过,但测试未在cucumber+java for Selenium webdriver测试中运行。在控制台中,我收到以下消息

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^User navigate to shopping page$")
public void user_navigate_to_shopping_page() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^user enters data$")
public void user_enters_data() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^clicks on search button$")
public void clicks_on_search_button() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^product should be displayed$")
public void product_should_be_displayed() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}
我写了下面的跑步者课程

package stepDefinition;
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;


@RunWith(Cucumber.class)
@CucumberOptions(
        monochrome=true,
        features = "src/main/resources/feature",
    glue="src/test/java/stepDefinition",
    tags={"@tag2"},
    dryRun = false)
public class TestRunner {   
}
我还将附上该项目的目录结构截图

特征文件是

[![Feature: Checking Functionality
This is a demo test

@tag2
Scenario: Test Login
    Given User navigate to shopping page
    When user enters data
    And clicks on search button
    Then product should be displayed

您给出胶水值的方式不正确。你必须给出java包格式。请尝试使用
glue=“stepDefinition”

如果您当前的步骤定义包中有一个包,那么可以说步骤包含代码。然后胶水变成
“stepDefinition.steps”


您应该将功能移动到test\resources文件夹。

您正试图解决一个难题。也就是说,您正在尝试修复一些从未奏效的问题

我的方法是从有效的东西开始,然后转换有效的解决方案,直到它支持您的用例。如果我不确定该怎么做,我会用很小的步骤来做


工作的起点是Cucumber团队提供的Java框架。克隆/下载可以在这里找到:

我也遇到了同样的问题,我尝试了评论中提供的修复程序以及上面的修复程序。还有一个地方需要查看,那就是步骤定义类。 查看我的步骤定义时,我发现^symbol后面有多余的空格。我删除了空格,测试成功

下面是我收到问题时的代码。我删除了cap(^)符号后的空格


@给定(“^I open(.*)$”

您可能需要检查您创建的包。确保为每个类、测试运行器类、步骤定义类和功能创建不同的包

我在尝试与我的软件包建立通用关系时遇到了类似的问题,例如(comccumber.feature、comccumber.step和comccumber.runner)

相信这会有帮助


非常感谢您将stepdefinition类和test runner类放在一个包中

您好

您是否尝试将feauture移到/test branch?下?。此外,在intelliJ中,您可以配置模块设置并标记测试和代码文件夹,Eclipse中是否有类似的功能?我尝试移动测试中的功能,但没有成功:(我不确定你的第二个问题我能成功地执行功能文件,但不能执行运行程序文件这就是我目前遇到的问题非常好,这是我的问题!很难找到一个教程,他们说这两个地方必须完全相同。这样你可以看到它第一次运行..当什么都不起作用时..这起作用..那胶水是一种很难管理的东西