Cucumber-为什么我的步骤定义没有被识别

Cucumber-Why my step definition is not getting identified

我已经写了一个步骤定义文件,但仍然没有被识别,下面是我的功能,步骤定义,运行文件。

Feature: Google Search feature

Scenario: To verify search bar functionality

Given user is on google search page
When user enters a search keyword in a search bar
And user clicks on Enter keyboard button
Then search results are displayed
Then Close the browser
package com.mavenDemo;

import java.awt.Robot;
import java.awt.event.KeyEvent;

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefination {

WebDriver driver;

@Given("^user is on google search page$")
public void user_is_on_google_search_page() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    System.setProperty("webdriver.chrome.driver", "F://chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://www.google.com");

}

@When("^user enters a search keyword in a search bar$")
public void user_enters_a_search_keyword_in_a_search_bar() throws Throwable {

    driver.findElement(By.name("q")).sendKeys("Test");
}

@And("^user clicks on Enter keyboard button$")
public void user_clicks_on_Enter_keyboard_button() throws Throwable {

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_ENTER);
}

@Then("^search results are displayed$")
public void search_results_are_displayed() throws Throwable {
    boolean searchText = driver.findElement(By.xpath("//span[@class='wUrVib']")).getText().contains("Test");
    Assert.assertTrue(searchText);

}

@Then("^Close the browser$")
public void close_the_browser() throws Throwable {
    driver.quit();

}

}

package com.mavenDemo;

import org.junit.runner.RunWith;

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

 @RunWith(Cucumber.class)
 @CucumberOptions(features = 
  "C:/Users/BR/workspace/com.mavenDemo/src/main/java/Login.features", 
  glue = {
    "/com.mavenDemo/src/main/java/com/mavenDemo/StepDefination" })
 public class TestRunner {

 }

不识别步骤定义文件可能是什么原因?

我已经仔细检查了代码,但我找不到解决方案也尝试了为类似问题提供的解决方案,但即使这样也没有用 请帮我解决这个问题。

谢谢

我找到答案了!! 错误出现在测试运行器文件中,在胶水中指定步骤定义路径时,我们需要指定文件夹名称而不是测试运行器路径,

将胶水更改为

glue = {"com.mavenDemo" }

谢谢。

请从粘合路径中删除 /com.mavenDemo