首页 > 解决方案 > Cucumber+Serenity “您可以使用下面的代码片段实现缺少的步骤”

问题描述

我开发了一个带有 serenity-bdd 和 cucumber 的测试自动化,用于移动测试。我的问题在下面。

TEST PENDING: User can login with credentials
---------------------------------------------------------------------------------

cucumber.runtime.junit.UndefinedThrowable: The step "User launch the app" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "User sees the login page" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "User enters asdf@hotmail.com to username input" is undefined

cucumber.runtime.junit.UndefinedThrowable: The step "User enters 123123 to password input" is undefined

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


You can implement missing steps with the snippets below:

**NECESSARY METHODS IMPLEMENTATION** 

虽然我已经实现了这个方法,但我又得到了这个。我的跑步者、cucumbersteps 和功能文件如下所示。

亚军:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources/features/", glue = "cucumbersteps")
public class EbebekRunner {

}

黄瓜步骤:

class LoginSteps {

  @Steps
  EbebekLoginSteps ebebekLoginSteps;

  @Given("^User launch the app$")
  public void user_launch_the_app() {
    ebebekLoginSteps.launchApp();
  }

  @When("^User sees the login page$")
  public void user_sees_the_login_page() {
    ebebekLoginSteps.confirmLoginPage();
  }

  @Then("^User enters (.*) to username input$")
  public void user_enters_to_username_input(String userName) {
    ebebekLoginSteps.enterUserName(userName);
  }

  @And("^User enters (.*) to password input$")
  public void user_enters_to_password_input(String password) {
    ebebekLoginSteps.enterPassword(password);
  }

}

特征:

Feature: Login App

  Background:
    Given User launch the app

  Scenario Outline: User can login with credentials

    When User sees the login page
    Then User enters <username> to username input
    And User enters <password> to password input

    Examples:
      | username         | password |
      | asdf@hotmail.com | 123123   |

我的项目结构如下所述。

在此处输入图像描述

我试图将胶水更改为 {"cucumbersteps"} 但没有任何改变。我不明白为什么会调用问题。谁能帮我?

标签: javacucumbergherkinserenity-bdd

解决方案


老实说,这种类型的错误很棘手,并且可能由于多种原因而发生(例如,将运行器、步骤或功能放在测试文件夹之外),但是,根据您共享的信息,尝试在其中添加功能文件的名称路径:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources/features/yourfile.feature",
        glue = "stepdefinitions")

如果您在步骤定义文件夹中有目录,则必须执行以下操作:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources/features/yourfile.feature",
            glue = "stepdefinitions/your_directory")

推荐阅读