1
votes

Im trying to run a simple feature file with java and intellij and I cant seem to get it working.

Ive set up my Cukes test runner class

package config;

    import cucumber.api.CucumberOptions;
    import cucumber.api.junit.Cucumber;
    import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true,
    features = {"src/test/resources/features/"},
    dryRun = false,
    glue = "com.ecs.googleuat"
)
public class RunCukesTest {
}

feature: Feature: home Scenario: home Given I am on the home page

step definitions:

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;

public class MyStepdefs {
@Given("^I am on the home page$")
public void iAmOnTheHomePage() {
    System.out.println("Hello");
}
}

project structure:

enter image description here

Im using a maven project with the java cucumber plugins.

When I run the feature file I get the following error:

Undefined step: Given I am on the home page

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

You can implement missing steps with the snippets below:

@Given("^I am on the home page$")
public void i_am_on_the_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}

Process finished with exit code 0

Please help me understand what Im doing wrong.

Thanks

1
what is the glue com.ecs.googleuat? - Vinay Prajapati
can you add a, image of the expanded project structure especially the java part? - Grasshopper
@VinayPrajapati this is the groupID, i thought that was the glue, I'm obviously wrong - mogoli
After removing the groupId what error is it giving? - Vinay Prajapati
this means that cucumber is unable to find your glue. try creating a directory inside your src/test/java and appending that to the location provided in your runner glue = "com.ecs.googleuat" - Marit

1 Answers

1
votes

Not 100% sure but I think the issue is with the method name. The easy solution just copy-paste the suggested step definition inside MyStepdefs and remove exception and add your println and then run. Also try removing the glue com.ecs.googleuat you added.

Please follow this for further help!

Though I would strictly recommend going ahead with java-8.

Anyways, If you are comfortable with Java-8. Remove the glue inRunCukesTest.java. And update your MyStepdefs.java

  public class MyStepdefs implements En {
      public Stepdefs() {
        Given("^I am on the home page$", () -> {
           System.out.println("Hello");
        });
     }
 }

En automatically implements default Glue for you.

Also, use appropriate dependencies. Follow this for same.

Edit: For Java 8 please make sure that if you are using IntelliJ Idea, then Project SDK is enabled to 1.8.

enter image description here