Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber JVM undefined step

I can't execute a simple test with cucumber for a project. I am on Intellij 13 Community, with cucumber plugin.

I wrote my feature file in my features directory, I have also implemented my steps, creating them with the help of the plugin. And my steps in the feature files are recognized by intellij, which can navigate and go to the step implementation.

But when I try to run my scenario, it always fails because for each step, it says "Undefined step : ".

Here is how is organized my project :

file organization

And as I said before, you can see that my steps are recognized by Intellij :

feature file

How is that possible, and how can I correct this?

Any help would be great!

EDIT

Now that I added options to my runner :

@CucumberOptions(  monochrome = true,
        features = "src/test/resources/features/",
        format = { "pretty","html: cucumber-html-reports",
                "json: cucumber-html-reports/cucumber.json" },
        dryRun = false,
        glue = "fr.tlasnier.cucumber" )

It works!

Yet, I noticed that before that, I had two scenario outline. One worked perfectly, the other one could not find step definition!

Really weird, since there were some steps in both scenario.

like image 311
Thibault Avatar asked Feb 13 '14 11:02

Thibault


People also ask

How do you fix a undefined step in Cucumber?

If Cucumber is telling you that your steps are undefined, when you have defined step definitions, this means that Cucumber cannot find your step definitions. You'll need to make sure to specify the path to your step definitions (glue path) correctly.

Why steps are skipped in Cucumber?

Cucumber is correctly indicating that the scenario has failed, which is being picked up by IntelliJ, as the summary at the top ("Done: Scenarios 1 of 1 failed") is correct. The scenario and feature failures are not being registered by the test runner, so the skipped state of the steps is being propagated to them.

How do you define step definitions in cucumbers?

Add a Step Definition file 1) Create a new Class file in the 'stepDefinition' package and name it as 'Test_Steps', by right click on the Package and select New > Class. Do not check the option for 'public static void main' and click on Finish button. Take a look at the message in the console window.

How do you skip steps in Cucumber Java?

'next' skips everything below, it is kind of like 'return', which might work too. Program the steps like you usually would, but in the first line of the step, make an 'if' statement like the one above to not run the code below if you don't want to.


2 Answers

@RunWith(Cucumber.class)

@CucumberOptions(  monochrome = true,
                         tags = "@tags",
                     features = "src/test/resources/features/",
                       format = { "pretty","html: cucumber-html-reports",
                                  "json: cucumber-html-reports/cucumber.json" },
                        dryRun = false,
                         glue = "fr.tlasnier.cucumber" )

public class RunCucumber_Test {
  //Run this
}
like image 182
Bala Avatar answered Oct 14 '22 00:10

Bala


The class in which the steps are defined should be public. Anything else would throw the undefined step error.

like image 39
Vel Ganesh Avatar answered Oct 13 '22 22:10

Vel Ganesh