问题
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
and the feature file is
[![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
回答1:
The way you have given the value of glue is incorrect. You have to give in java package format. Try glue = "stepDefinition"
instead.
If you had a package inside your current stepDefinition package lets say steps which has the code. Then glue becomes "stepDefinition.steps"
You should move your features to the test\resources folder.
回答2:
I got the same issue and I tried the fixes provided in the comments along with the above fix there is one more area to look at which is step definiton class. while looking at my step definition I observed that there are extra spaces after the ^ symbol .I removed the spaces and the test was successfull.
Below was my code when I got the issue .I removed the space after the cap (^) symbol
@Given("^ I open (.*)$")
回答3:
You are trying to solve a hard problem. That is, you are trying to fix something that never worked.
My approach would be to start with something that worked and then transform that working solution until it supports your use case. I would do that in very small steps if I am unsure about what to do.
A working starting point is the Java skeleton provided by the Cucumber team. Clone/download it can be found here: https://github.com/cucumber/cucumber-java-skeleton
回答4:
You might want to check your package created. Make sure you create a different package for each class, test runner class, step definition class and your feature.
I run into a similar problem while trying to have a universal relationship with my packages e.g (comCucumber.feature, comCucumber.step and comCucumber.runner).
Trust this would helpful.
Many thanks
回答5:
Hi Keep stepdefinition class and test runner class in one package
来源:https://stackoverflow.com/questions/40212449/getting-scenario-and-steps-undefined-in-cucumber-with-java