使用java在黄瓜中获取未定义的场景和步骤

2022-01-22 00:00:00 selenium cucumber java junit

自 2 天以来,我一直在与此作斗争.我的测试显示通过,但测试没有在 cucumber+java 中运行 Selenium webdriver 测试.在控制台中,我收到以下消息

I have been battling with this since 2 days. My test is shown passed but the test is not running in cucumber+java for Selenium webdriver test. In the console I am getting following message

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

我已经写了以下跑步者课程

I have written following runner class

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 {   
}

我还会附上项目目录结构的截图

I will also attach the screenshot of directory structure of the project

特征文件是

[![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

推荐答案

你给glue的值的方式不对.您必须提供 java 包格式.试试 glue = "stepDefinition" 代替.

The way you have given the value of glue is incorrect. You have to give in java package format. Try glue = "stepDefinition" instead.

如果您当前的 stepDefinition 包中有一个包,可以说 steps 包含代码.然后胶水变成"stepDefinition.steps"

If you had a package inside your current stepDefinition package lets say steps which has the code. Then glue becomes "stepDefinition.steps"

您应该将您的功能移动到 testesources 文件夹.

You should move your features to the testesources folder.

相关文章