黄瓜1.2.4没有找到步骤定义:"您可以使用下面的片段实现缺少的步骤" (2016)

时间:2016-05-26 21:50:30

标签: cucumber java-7 cucumber-java

我试图在类似UNIX的情况下使用Maven运行Cucumber(不幸的是我被迫使用Windows,尽管cmd.exe具有相同的结果)命令行:

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

结果:

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();
}

我已经查看了所有Google / SO搜索的主要内容以及类似的错误消息。许多人(例如Cucumber can't find steps when running a single featureCucumber not finding step definitions)说要使用-r和--require参数指定我的步骤定义,但它们似乎已经在某些时候从Cucumber中删除了,因为我得到了Unknown option: -r错误。 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

许多其他答案表示,如果错误地定义了@CucumberOptions glue参数,则会发生此错误(奇怪)。但是我尝试过以下胶水,但没有一种能起作用:

-Dcucumber.options

我也尝试过:

  • @Given("that I have my animals")中定义 - 胶水。
  • 更改我的源代码 目录结构为src / test / java / example / automation_cuke, 的src /主/爪哇/示例/ automation_cuke, src / test / resources / example / automation_cuke等。
  • 放我的.feature 文件在主...资源。
  • @Given中的各种不同文本,例如Feature: My animals Sample Sample test to use as basis for conversion Scenario: My animals Given that I have my animals

这是我的项目结构。我确保资源结构与代码的其余部分as per this answer匹配:

cucumber-demo project structure

sample_text.feature:

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();
    }
}

MySampleTest.java:

<?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>

的pom.xml:

tiff("LEAT_2.tiff", width = 800, height = 600, units = 'px')
LEAT <- hist(data)
plot(LEAT, 
     col= "darkblue", 
     xlim=c(0,30), 
     main="Leading Edge Arrival Times", 
     xlab="Hours", 
     ylab="Frequency")  
mtext("(Using predicted 90th percentile streamflow)", side=3)
dev.off()

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:4)

您需要为黄瓜选项设置features属性才能生效。

用以下代码替换黄瓜选项注释:

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

应该让它发挥作用。如果没有,请更新帖子。

更新:

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

<强>更新

我认为你的项目存在的问题是它无法在类路径上找到测试类(以及步骤def类)。我不明白你为什么要定义一个CLASSPATH系统变量。这可能是这个问题的原因。但是,PATH变量应保留,不应包含对特定项目的任何引用

尝试删除CLASSPATH变量并使用以下内容替换plugins标记:

 <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>

我可以使用java 8以及java 7在多个窗口环境中运行它。让我发布!

答案 1 :(得分:3)

您的设置非常复杂。考虑Gall’s Law,我会重新启动并构建有效的东西。 https://github.com/cucumber/cucumber-java-skeleton

提供了一个小型入门项目

下载/克隆并运行

mvn test

这应该给你一个缺失的步骤,但它也应该给你一些定义的步骤。查看源代码并在src/test/java/skeleton/Stepdefs.java

中添加缺少的步骤