【问题标题】:Cucumber JVM Undefined Step Not resolvingCucumber JVM未定义步骤未解决
【发布时间】:2015-09-16 13:53:32
【问题描述】:

我遇到了 Cucumber JVM 无法获取步骤定义的问题。我在 Runner 文件中有 @CucumberOptions 。我的功能文件也有@smokeTest 标签。 对我来说问题仍然存在。请帮忙!我这几天一直在尝试解决这个问题。

Maven 和 Java 版本:

Apache Maven 3.0.4 Java 版本:1.6.0_65,供应商:Apple Inc.

项目结构:

  1. Demo --> src --> test --> java --> com.smoke.test --> Runner.java | SmokeTestStepDef.java
  2. Demo --> src --> test --> 资源 --> featureDemo.feature

跑步者文件:

包 com.smoke.test;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(format={"pretty","html:reports/test-report"},tags= "@smokeTest")

public class Runner {
}

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.demo</groupId>
    <artifactId>cumcumberdemo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.41.0</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.1.7</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>1.1.7</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.7</version>
        <scope>test</scope>
    </dependency>
    </dependencies>

</project>

【问题讨论】:

  • 你如何编写你的.feature?因为它在正确的路径上,但似乎黄瓜无法识别步骤,您可以添加您的问题吗?
  • @PedroHenrique : 你的意思是特征文件中的 Gherkin 脚本是什么?
  • 是的,有一次我遇到过这样的问题,错误出在 .feature 文件上
  • 功能:两个数字相加场景:验证两个数字相加给定我有一个计算器当我将 2 和 3 相加时,结果是 5
  • @justCurious 你能用你的实际功能文件(包括黄瓜标签,如果有的话)编辑你的问题吗?

标签: maven selenium cucumber-jvm


【解决方案1】:

featureDemo.feature 移动到src/test/resources/com/smoke/test 下。

正如 Eugene 提到的,这看起来像是一个胶水问题,但从您的 cmets 来看,您的项目中似乎有另一个功能文件隐藏了问题,即它实际上是无法找到的功能文件。

【讨论】:

    【解决方案2】:

    我认为您还必须在 @CucumberOptions 中定义粘合路径。这是您的步骤定义所在的位置。它被描述为here

    【讨论】:

    • 感谢 Eugene S. 的回复。也试过了。不工作。在发布这个问题之前,我对 StackOverflow 进行了研究。
    • @justCurious 您是否尝试将标签更改为tags = {"@smokeTest"}(带花括号)?
    • 是的,还是不行。也完全删除了标签,但问题仍然存在!
    • 不。我正在使用 IntelliJ (CE),这就是我在右键单击时得到的 -> 在功能文件上运行 - 1 个场景(1 个未定义)3 个步骤(3 个未定义)0m0.000s 未定义步骤:给定示例功能文件已准备好未定义步骤:当我运行功能文件时
    • @justCurious 好吧,如果它说“未定义”,这意味着黄瓜找不到步骤定义。确保设置正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多