Java 黄瓜特征文件未识别步骤

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35564839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:50:06  来源:igfitidea点击:

Cucumber feature file does not identify the steps

javaeclipseseleniumcucumbergherkin

提问by Ash

I have written my firsy cucumber feature file. When I run the feature file as Cucumber Feature, I get below errors

我已经编写了我的 firsy 黄瓜功能文件。当我将功能文件作为 Cucumber 功能运行时,出现以下错误

  1. "WARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead." - I used "plugin" in my @CucumberOptions of runner class, but still getting the same error
  1. “警告:不推荐使用 Cucumber-JVM 的 --format 选项。请改用 --plugin。” - 我在 runner 类的 @CucumberOptions 中使用了“插件”,但仍然出现相同的错误

2.It says I do not have any scenario and steps Feature: Validate Modular GUI pages

2.它说我没有任何场景和步骤功能:验证模块化 GUI 页面

Scenario: Validate Login Page # C:/Selenium/RegressionTest/ModularRegression/src/GUI/features/Validate.feature:3 Given: Modular GUI is opened When: Validate the login page Then: Login to the Modular

场景:验证登录页面 # C:/Selenium/RegressionTest/ModularRegression/src/GUI/features/Validate.feature:3 给定:打开模块化 GUI 时间:验证登录页面 然后:登录到模块化

0 Scenarios 0 Steps

0 场景 0 步骤

  1. I'm not getting snippets for my steps.
  1. 我没有得到我的步骤的片段。

I have added following jars to the library Jars

我加入以下jar添加到库

This is my runner class, package GUI;

这是我的跑步者类,包 GUI;

import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        format = {"pretty", "json:target/"},
        features = {"src/GUI/"}
        )
public class GUIRunner {

}

This is my feature file,

这是我的功能文件,

Feature: Validate Modular GUI pages

  Scenario: Validate Login Page
    Given: Modular GUI is opened
    When: Validate the login page
    Then: Login to the Modular

I would really appreciate if someone can point out what is missing in my code.

如果有人能指出我的代码中缺少什么,我将不胜感激。

Thank you very much

非常感谢

[EDITED] This is the actual error:

[已编辑] 这是实际错误:

WARNING: Cucumber-JVM's --format option is deprecated. Please use --plugin instead. Feature: Validate Modular GUI pages

Scenario: Validate Login Page # C:/Selenium/RegressionTest/ModularRegression/src/GUI/features/Validate.feature:3 Given: Modular GUI is opened When: Validate the login page Then: Login to the Modular

0 Scenarios 0 Steps 0m0.000s

警告:不推荐使用 Cucumber-JVM 的 --format 选项。请改用--plugin。功能:验证模块化 GUI 页面

场景:验证登录页面 # C:/Selenium/RegressionTest/ModularRegression/src/GUI/features/Validate.feature:3 给定:打开模块化 GUI 时间:验证登录页面 然后:登录到模块化

0 场景 0 步骤 0m0.000s

采纳答案by Ash

I had an extra ":" in my feature file after Given, When and Then.

在 Given、When 和 Then 之后,我的功能文件中有一个额外的“:”。

It's working now.

它现在正在工作。

回答by Thomas Sundberg

You are missing your feature files in your class path.

您的类路径中缺少功能文件。

You don't tell us how you are running Cucumber. But if you would run it as a part of a Maven build, which is among the easier options, you would like to store your feature file in

你没有告诉我们你是如何运行 Cucumber 的。但是,如果您将它作为 Maven 构建的一部分运行,这是更简单的选择之一,您希望将您的功能文件存储在

./src/test/resources/GUI

./src/test/resources/GUI

An easy way to get started is to download the getting started project from GitHub, https://github.com/cucumber/cucumber-java-skeleton

一个简单的入门方法是从 GitHub 下载入门项目,https://github.com/cucumber/cucumber-java-skeleton

It will give you a a working project that you can modify to contain your problem.

它将为您提供一个工作项目,您可以对其进行修改以包含您的问题。

回答by Bhuvanesh Mani

Where are your step definitions located? Try adding the tag 'glue' like below

您的步骤定义位于何处?尝试添加标签“胶水”,如下所示

@RunWith(Cucumber.class)
@CucumberOptions(
        format = {"pretty", "json:target/"},
        features = {"src/GUI/"},
        glue = {"path/to/steps"} 
        )
public class GUIRunner {

}

回答by wondersz1

Just to add to the existing answers: remember to write "Scenario: " before writing actual code of the step. That might seem absolutely trivial, but without it you'll always be getting "0 features, 0 steps" message.

只是添加到现有答案中:记住在编写步骤的实际代码之前写下“场景:”。这可能看起来绝对微不足道,但如果没有它,您将始终收到“0 个功能,0 个步骤”的消息。

Source: https://www.youtube.com/watch?v=WuTKWwD37Tg

来源:https: //www.youtube.com/watch?v=WuTKWwD37Tg

回答by Charan Rao

Please add tags = {"@SmokeTest"}or tags = {"@RegresionTest"}

请添加tags = {"@SmokeTest"}tags = {"@RegresionTest"}

回答by Ch Rajeshwar Reddy

please add tags= {"@SmokeTest","@RegressionTest"}in @CucumberOptions()

请加 tags= {"@SmokeTest","@RegressionTest"}@CucumberOptions()

回答by TheSociety

Replace formatwith pluginas format option was deprecated from v1.2.0 onwards on 30-October-2014. Example below -

使用插件替换格式作为格式选项已于30-October-2014v1.2.0 开始弃用。下面的例子 -

@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features/functional/",
                     glue = {"com.Hymansparrow.automation.steps_definitions.functional" },
                   plugin = { "pretty","json:target/cucumber-json/cucumber.json",
                            "junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
                   tags = { "@BAMS_Submitted_State_Guest_User" },
                   strict = false,
                   dryRun = false,
               monochrome = true)