cucumberjava-7cucumber-java

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


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:

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!


Solution

  • 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