Cucumber 1.2.4 not finding step definitions: "You can implement missing steps with the snippets below" (2016)
Asked Answered
B

5

7

I'm trying to run Cucumber with Maven on a UNIX-like (unfortunately I'm forced to use Windows, though cmd.exe has the same results) command line:

mvn clean test -Dcucumber.options="src/test/resources/com/example/sqa/automation_cuke/pages/sample_test.feature"

Results in:

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
...
[INFO] --- exec-maven-plugin:1.2.1:java (default) @ sqa.automation_cuke ---
Feature: My animals Sample
  Sample test to use as basis for conversion

  Scenario: My animals           # sample_test.feature:4
    Given that I have my animals

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


You can implement missing steps with the snippets below:

@Given("^that I have my animals$")
public void that_I_have_my_animals() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

I've looked at all the top Google/SO searches for this and similar error messages. Many, such as Cucumber can't find steps when running a single feature and Cucumber not finding step definitions, say to specify my step definitions with the -r and --require parameters but they appear to have been removed from Cucumber at some point, as I get an Unknown option: -r error.

Many other answers say that this error (strangely) happens when the @CucumberOptions glue parameter is defined incorrectly. But I've tried the following glues and none have worked:

sqa.automation_cuke.pages path:sqa.automation_cuke.pages classpath:sqa.automation_cuke.pages com.example.sqa.automation_cuke.pages classpath:com.example.sqa.automation_cuke.pages path:com.example.sqa.automation_cuke.pages C:/development/cucumber-demo/src/main/java/com/example/sqa/automation_cuke/pages src/main/java/com/example/sqa/automation_cuke/pages classpath:C:/development/cucumber-demo/src/main/java/com/example/sqa/automation_cuke/pages classpath:src/main/java/com/example/sqa/automation_cuke/pages path:src/main/java/com/example/sqa/automation_cuke/pages C:\\development\\cucumber-demo\\src\\main\\java\\com\\example\\sqa\\automation_cuke\\pages src\\main\\java\\com\\example\\sqa\\automation_cuke\\pages classpath:src\\main\\java\\com\\example\\sqa\\automation_cuke\\pages path:src\\main\\java\\com\\example\\sqa\\automation_cuke\\pages

I've also tried:

  • Defining --glue in -Dcucumber.options.
  • Changing my source code directory structure to src/test/java/example/automation_cuke, src/main/java/example/automation_cuke, src/test/resources/example/automation_cuke, etc.
  • Putting my .feature file in main...resources.
  • Various different texts in @Given, such as @Given("that I have my animals").

This is my project structure. I made sure the resource structure matches the rest of the code as per this answer:

cucumber-demo project structure

sample_text.feature:

Feature: My animals Sample
  Sample test to use as basis for conversion

  Scenario: My animals
    Given that I have my animals

MySampleTest.java:

package com.example.sqa.automation_cuke.pages;

@RunWith(Cucumber.class)
@CucumberOptions(glue = {"com.example.sqa.automation_cuke.pages"})
public class MySampleTest {

    @Given("^that I have my animals$")
    public void that_I_have_my_animals() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        System.out.println("MySampleTest.that_I_have_my_animals() ran!");
        new MySample().printMySample();
        throw new PendingException();
    }
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>sqa.automation_cuke</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cucumber-jvm.version>1.2.4</cucumber-jvm.version>
        <selenium.version>2.53.0</selenium.version>
        <junit.version>4.12</junit.version>
    </properties>

    <build>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executableDependency>
                        <groupId>info.cukes</groupId>
                        <artifactId>cucumber-core</artifactId>
                    </executableDependency>
                    <mainClass>cucumber.api.cli.Main</mainClass>
                    <arguments>
                        <argument>--plugin</argument>
                        <argument>junit:target/cucumber-junit-report/allcukes.xml</argument>
                        <argument>--plugin</argument>
                        <argument>pretty</argument>
                        <argument>--plugin</argument>
                        <argument>html:target/cucumber-html-report</argument>
                    </arguments>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>info.cukes</groupId>
                        <artifactId>cucumber-core</artifactId>
                        <version>${cucumber-jvm.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber-jvm.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber-jvm.version}</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber-jvm.version}</version>
        </dependency>
        <!-- http://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber-jvm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.7</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</project>

Any help would be appreciated!

Balthasar answered 26/5, 2016 at 21:50 Comment(0)
C
6

You have a very complicated setup. Thinking of Gall’s Law, I would do a restart and build on something that works. A small getting started project is available at https://github.com/cucumber/cucumber-java-skeleton

Download/Clone it and run

mvn test

This should give you a missing step but it should also give you some steps defined. Look in the source code and add the missing step in src/test/java/skeleton/Stepdefs.java

Championship answered 27/5, 2016 at 6:39 Comment(2)
Thanks! I'll be sure to apply Gall's Law more in the future! I just sent it around to my coworkers haha :)Balthasar
Gall's "Law" is not a law. Use at your own discretion.Unconsidered
C
4

You need to set the features attribute for cucumber options for it to work.

Replacing your cucumber options annotation with:

@CucumberOptions(features = {"classpath:com/example/sqa/automation_cuke/pages/sample_test.feature"}, glue = {"com.example.sqa.automation_cuke.pages"},

should make it work. Please update the post if it does not.

UPDATE:

SampleTestStepDefiniton.java

package com.example.sqa.automation_cuke.pages;

import cucumber.api.java.en.Given;

public class SampleTestStepDefinition {

    @Given("^that I have my animals$")
    public void that_I_have_my_animals() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        System.out.println("MySampleTest.that_I_have_my_animals() ran!");   
    }
}

MySampleTest.java

package com.example.sqa.automation_cuke.pages;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(glue = { "com.example.sqa.automation_cuke.pages" }, features = {
        "classpath:com/example/sqa/automation_cuke/pages/sample_test.feature" })
public class MySampleTest {

}

sample_test.feature

Feature: My animals Sample
  Sample test to use as basis for conversion

  Scenario: My animals
    Given that I have my animals

UPDATE

I think the problem with your project is that it is not able to find the test classes(as well as step def classes) on classpath. I do not understand why you have to define a CLASSPATH system variable. That could be a reason for this issue. PATH variable however should stay and should not contain any reference to a specific project

Try getting rid of CLASSPATH variable and replacing your plugins tag with the following:

 <plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <encoding>utf8</encoding>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>test-jar</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18</version>
    </plugin>
</plugins>

I could get it running on multiple window environments with java 8 as well as java 7. Keep me posted!

Charlottecharlottenburg answered 26/5, 2016 at 22:32 Comment(13)
Thanks. That gave me the same "missing steps" error, though. I also tried your CucumberOptions with mvn clean test without any parameters and got Tests run: 0, Failures: 0, Errors: 0, Skipped: 0Balthasar
I tried to execute your sample test class and got this error. Classes annotated with @RunWith(Cucumber.class) must not define any Step Definition or Hook methods. Their sole purpose is to serve as an entry point for JUnit. Step Definitions and Hooks should be defined in their own classes. This allows them to be reused across features. Offending class: class com.example.sqa.automation_cuke.pages.MySampleTest Once I separated the step definition from the main test class file, I was able to execute it. Hope this helps.Charlottecharlottenburg
Thanks. I deleted @RunWith(Cucumber.class) from MySampleTest and added it to MySample (I also had to remove junit from the test scope in my pom) but got the same result. What new class did you create (if any) when you "separated the step definition from the main test class file"?Balthasar
You should not delete @RunWith(Cucumber.class) from your test class but instead move the @Given Implementation to a step definition class. I created a new class as 'MySampleStepDefinition'. Also, You need to delete the throw new PendingException() from your step definition implementation. This is auto-generated and prompts to implement the step. i believe, that having this line of code is the main reason your code is failingCharlottecharlottenburg
I deleted the new PendingException() block and it threw the same message that it throws in the OP. Can you pastebin me your working code? I don't know where MySampleStepDefinition should be located, how it differs from MySample, or what's even supposed to be in it.Balthasar
How are you building it? I pasted the code you added to your answer and I'm still getting the missing steps error from the OP when I build with mvn clean test -Dcucumber.options="src/test/resources/com/example/sqa/automation_cuke/pages/sample_test.feature". And plain mvn clean test still doesn't execute the tests. SampleTestStepDefinition is in main/java/.../pagesBalthasar
I am using maven in a windows environment. And the path for feature file matches as well.Charlottecharlottenburg
SampleTestStepDefinition should be in src/test/java..../pages. Same as MySampleTest. We specify the package containing step def classes by glue paramterCharlottecharlottenburg
Did you have to edit your classpath? My system CLASSPATH variable is C:/Program Files/[redacted];.;C:/development/cucumber-demo. Not very familiar with Windows. Also I tried moving SampleTestStepDefinition from src/main/java/.../pages to src/test/java/.../pages and that didn't help.Balthasar
No. If you are doing that as a maven project; dependencies that the project needs should be declared in pom.xml. Can you share the dependencies that you have defined?Charlottecharlottenburg
Sure, I just added my pom with dependencies (before I truncated the dependencies) to the OPBalthasar
Thanks for all your help! I learned a lot about Cucumber from this!Balthasar
I ended up downloading a skeleton project. I still don't know why the one I was trying to make myself didn't work, but the skeleton project will be a fine base for what I'm doing.Balthasar
C
2

I also faced same issue then i realize the package which imported for runner class were different than Step definition class

SO
if for runner class you are using io package as below

import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;

Then you should also use the same io package in step definitions

import io.cucumber.java.en.Given;

I did the mistake of importing API package

import cucumber.api.java.en.Given;
Corallite answered 25/9, 2021 at 14:3 Comment(2)
God bless you for posting this🤣. I literally tried every thing out and this is what that was happening all along.Stratus
that solved my problem. the readers should check this out. thxWelby
B
0

SOLUTION

I tried many times and this is a solution.

Breadboard answered 3/1, 2023 at 14:15 Comment(0)
N
0

I faced same issue and I just updated version of cucumber-junit, cucumber -java to 7.11.2 in pom.xml and rebuild project. Then it resolved and my feature steps executed successfully.

Nassi answered 30/3, 2023 at 12:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.