25

I'm trying to follow this article to match Cucumber specs with step definitions in IntelliJ.

When I press Alt+Enter, I see Inspection 'Undefined Step' options. However, I should see the intention action Create Step Definition.

I thought I had the Cucumber IntelliJ plugin installed, so that shouldn't be a problem. Any help is greatly appreciated.

niftygrifty
  • 3,452
  • 2
  • 28
  • 49

13 Answers13

43

Turns out I had the Gherkin plugin but not the Cucumber for Java plugin.

niftygrifty
  • 3,452
  • 2
  • 28
  • 49
  • Thank you! I just ran in to the same problem. I set up a new project, opened a .feature file, IntelliJ suggested to install a plugin for me with which I can edit that .feature file, so I let it do its thing. It only included Gherkin, but not Cucumber for Java. After manually including the CfJ plugin, it worked. – bcody Nov 16 '15 at 13:47
  • Ditto! I think it's silly for IJ to come bundled with the vanilla Gherkin plugin but not any Cucumbery plugins to go with it. IJ should come with CfJ (and maybe CfG too) which also bring in the Gherkin plugin as dependency. – romulusnr Dec 16 '15 at 22:55
  • 2
    I probably havve the same Problem but can't get a handle on it. I have imported gherkin as well as cucumber (groovy) via the maven importer and the jars were downloaded correctly but no way of using alt + enter for creating stepDev. how exactly did you guys proceed ? – Christoph Zabinski Mar 03 '16 at 19:04
  • To add to this, I accidentally had the SubSteps plugin installed, which seems to conflict with Cucumber for Java in interesting ways. Uninstalling that fixed the issues I had. – Tetrinity Nov 30 '17 at 11:47
14

I wasted around an hour to solve this. My issue was, Idea was able to navigate from feature to step file. But when I wanted to execute one cucumber test from feature file (Right click and Run Scenario), it was giving error as undefined steps.

Solution: In the Edit Configuration -> provide the Glue for the cucumber which should be absolute path till steps folder. Please see below screen shot

enter image description here

This fixed my problem of running feature file from Idea. Hope this helps others.

Sanjay Bharwani
  • 3,317
  • 34
  • 31
  • 1
    Thanks Sanjay. Also to include multiple step folders, enter the name with spaces in Glue textbox in intellij. – learner Dec 01 '17 at 04:23
  • My Configuration had been auto generated by Intellij on the right click -> Run. So I just deleted the configuration and re-ran the right click Run option – davidfrancis Sep 29 '18 at 09:22
  • 1
    This really helped me to solve the issue - a great pointer for the issue!! – Balaji Venkatachalam Feb 25 '21 at 22:06
  • @Sanjay I hit undefined scenarios issue, what should be input at glue? i have put the path till reaching the feature file like this but it does not helps "\src\test\resources\features\creating_todos" – user2201789 Aug 20 '21 at 03:11
  • @user12158726 Glue should point to the folder where your steps exists and the feature or folder path should point to the folder where your feature file exists. – Sanjay Bharwani Aug 20 '21 at 11:26
  • I found out just need to input the package name in glue. – user2201789 Aug 20 '21 at 12:17
3

Most probably you need to install the cucumber for java plugin, if already installed then you need to enable from File>>Settings>>pugins.

B. Jha
  • 31
  • 2
2

I had to uncheck the "Create separate module per source set" checkbox under the "Build, Execution, Deployment" -> "Build Tools" -> "Gradle" settings, and then rebuild the project.

Settings

Igor
  • 33,276
  • 14
  • 79
  • 112
1

"Undefined" step error message would appear if you import a new BDD project.

This error could appear due to two reasons.

  1. If you have not installed the "Cucumber for Java" plugin.
  2. If you import any BDD projects then it will not detect step definition file.

Solution: 1. If the plugin is not found then you need to install from the below location. File->Settings->Plugins->MarketPlace->Cucumber for Java 2. After Importing the project disable the plugin and enable once again in the Installed section under Installed.

Jagan
  • 79
  • 3
1

For me there was a collision between Sidesteps plugin and Cucumber plugin in Intellij and as a result *.feature file extension was taken over by the Sidesteps plugin and was expecting Sidesteps step definitions ignoring Cucumber step definitions. No clue what Sidesteps actually is. So went to IntelliJ settings and reassigned the *.feature extension to Cucumber Scenario type and then everything worked fine and Cucumber steps are recognized by Intellij now.

Ruby9191
  • 113
  • 1
  • 10
1

I had the same issue where all of a sudden my feature to step definition glue was missing. All i did was goto Run->Edit Configurations->and removed the cucumber java configuration and restarted IntelliJ. it worked fine.

Jarvic
  • 11
  • 1
0

I found that even with the Cucumber for Java plugin installed it was still generating only one step. I eventually uninstalled the Cucumber for Java plugin and reinstalled it and all step definitions were generated.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
David
  • 175
  • 1
  • 2
  • 13
0

The issue was fixed after updating the Intelij to the latest version and after updating the cucumber and gherkin intelij plugins

ThimiraR
  • 167
  • 2
  • 7
0
  1. Me not help not one of suggestions above. But i find if you start one test from runner the problem goes on (it is worked if you have runner for some tests( Runner is class that have line @CucumberOptions( features = "src/test/resources/stability_*****_features/", glue = "steps" )

  2. And may be the next line in config helped you^ in configurations i put line: --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter in Programm arguments line - it help me enter image description here

0

If still not working, you can add runner class

add -> runner package -> Main Runner class

-test
 -runner - Create this package
 -stepPackage
  -resources
   -features

enter image description here

@CucumberOptions(features = {"classpath:features"}, glue = {"stepDefinition"},
                 monochrome = false,dryRun = false)
public class MainRunner extends AbstractTestNGCucumberTests {
    
}

That is it. Just run this class first. Right mouse click and Run'MainRunner' Then it will work if you just go back and run Scenarios as well

ilia
  • 98
  • 1
  • 8
0

I had the same issue and was resolved by going to Run> Edit configuration> Before Launch then click on the add option "+" and add Build Project option. enter image description here

jamie Lue
  • 1
  • 1
0

The case for me was, Class is NOT defined as public ... i.e. The class where my step definitions are specified was not Public. Reason for removing Public modifier for class was -- I am using @Test from Junit5 and is recommending to remove Public for both class and methods.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 02 '23 at 13:11