Nobodyelse
Nobodyelse

Reputation: 99

Cucumber test.feature doesn't see my steps

I wanted to start testing with cucumber, created the simpliest test.feature file:

Feature: XYZ
 Scenario: S1
  When I am on x page
  Then I see the element

and create steps

import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

    public class MyStepdefs {
        @When("^I am on x page$")
        public void iAmOnXPage() {
            System.out.println("I'm on page");
        }

        @Then("^I see the element$")
        public void iSeeTheElement() throws Throwable {
            System.out.println("I see dead people");
        }
    }

I've all needed plugins installed: - Cucumber for Java - Cucumber for Groovy - Gherkin Structure of files is:

enter image description here

Moreover the test/java folder is marked as Test Source Folder in Maven. I also tried to restart IntelliJ and Reimport project in Maven, nothing helps. Any suggestions?

Upvotes: 0

Views: 2001

Answers (1)

Nobodyelse
Nobodyelse

Reputation: 99

Ok, I've found a solution, I created additional testRunner class:

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

@RunWith(Cucumber.class)
@CucumberOptions(
        features={"src/test/resources"}
)

public class testRunner {
}

It wasn't mentioned in few tutorials I've checked but found it in https://www.stevefenton.co.uk/2015/01/getting-started-with-bdd-intellij/ and after small changes (eg @Cucumber.Options -> @CucumberOptions) it worked:)

Upvotes: 2

Related Questions