user3166602
user3166602

Reputation: 31

Cucumber .feature file is not getting linked to stepDefinition.java in Eclipse

I have installed Natural 0.7.6 plug-in from eclipse marketplace and I have Windows 10. Eclipse version: Eclipse IDE for Java Developers Version: 2020-03 (4.15.0) Build id: 20200313-1211

Maven dependencies related to Cucumber:

    <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>5.7.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>   
  </dependencies>

.feature file

step definition file

  [1]: [https://i.sstatic.net/e22x3.png][1]
  [2]: https://i.sstatic.net/cAfLY.png

The .feature file complains about "No definition found for ". CTRL+CLICK on .feature file step is not navigating to stepDefinition file (screenshots attached). Am I missing any plugin? Is there any compatibility issues with Eclipse IDE version and the Cucumber plug-in I am using? I appreciate your help guys.

Upvotes: 2

Views: 34231

Answers (7)

Eduardo Toural
Eduardo Toural

Reputation: 77

Be sure that the step definition matches the Steps Definition Annotation in the "Steps" .java file.

Upvotes: 0

Vishu
Vishu

Reputation: 1

Suggestion:

  1. Please have a look at your Java and JRE versions to ensure they are both aligned in the IDE. For example, Java 11 and JRE-11 should be the same version number.

  2. The versions for cucumber-java and cucumber-junit should match as well and should be updated to the latest version.

Upvotes: 0

bhawukchauhan
bhawukchauhan

Reputation: 1

If you are not able to get to the relevant step definition method from Feature file by either F3 or CTRL+ Left Mouse Click, change the default editor of Feature file as below image to select correct Cucumber Editor

Upvotes: 0

egad
egad

Reputation: 21

With the Cucumber Eclipse plugin, cleaning the Cucumber project (Project > Clean...) made the Gherkin steps Ctrl+click-able again.

Upvotes: 2

Rajan Domala
Rajan Domala

Reputation: 143

Steps to make it work.

  1. Clear out all the cucumber related plugins(e.g. Natural 0.9, cucumber eclipse plugin 1.0.0.xxxxx). Please do follow the suggestion of restarting your eclipse.
  2. Go to Help --> Eclipse Market place --> Install 'cucumber-eclipse' plugin. Please do follow the suggestion of restarting your eclipse.
  3. Right click on your project --> Configure --> Convert to Cucumber project.
  4. Now try to navigate to your step definition by 'Ctrl+click' on test step in feature file

Edit: I also changed JRE system library to 1.8( I am not sure it has any influence to make cucumber work )

Upvotes: 6

UnknownBeast
UnknownBeast

Reputation: 979

You need a cucumber runner file first and inside that you need to glue the step definition file with the cucumber feature. The thing is that in cucumber if you place the feature file, step definition file and runner file in the same package then automatically, it will be able to map the steps from the step definition file with the feature file. But as per the screenshots, I can see that feature and step definition is present in the different packages. Please create a runner file as shown below

>

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

@RunWith(Cucumber.class)
@CucumberOptions(
 features = "<Directory path containing features>" 
 ,glue={"<Step definition package name>"}
 )    //  example: Features: src/test/resources/features, Glue: com.package.name.stepdefs

public class TestRunner {

}

TestRunner.java

Upvotes: 0

CMM
CMM

Reputation: 573

I had same problem that CTRL+Click was not working in feature files when I installed Natural plugin in Eclipse IDE. Later, I uninstalled Natural plugin, and installed "Cucumber Eclipse" plugin, and now I can perform ctrl+click on step name of feature file to navigate to the step definition file.

You can follow below stpes:

  1. Un-install Natural plugin

  2. Install Cucumber Eclipse plugin

Note: Below are my Eclipse version details. "Cucumber Eclipse" plugin may not be available for latest Eclipse version

Version: 2019-06 (4.12.0) Build id: 20190614-1200

Upvotes: 2

Related Questions