Java 步骤在黄瓜日食中没有匹配的胶水代码错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36400137/
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 17:50:19  来源:igfitidea点击:

Step does not have a matching glue code error in cucumber eclipse

javaeclipsecucumbercucumber-jvmcucumber-junit

提问by Chathurika Prabodani

I am trying to run a feature file which mentioned follows.

我正在尝试运行下面提到的功能文件。

Feature: Prove the concept of my script

  Scenario: My first Test
    Given This is my first step
    When This is my second step
    Then This is my third step

and when I run this feature file, it give an error that says the follows and the steps have been highlighted with the statement of "Steps does not have a glue code."

当我运行这个功能文件时,它给出了一个错误,说明以下步骤已经用“步骤没有胶水代码”的声明突出显示。

The error is shown as below. I want to run the above feature file and get to know the missing files of the feature.

错误如下所示。我想运行上述功能文件并了解该功能丢失的文件。

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/lexer/Encoding
    at cucumber.runtime.FeatureBuilder.read(FeatureBuilder.java:154)
    at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:115)
    at cucumber.runtime.model.CucumberFeature.loadFromFeaturePath(CucumberFeature.java:104)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:54)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:34)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:235)
    at cucumber.runtime.Runtime.run(Runtime.java:110)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: gherkin.lexer.Encoding
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 9 more

Please, I am a starter to cucumber and I want to resolve this problem. Please help me if you can.

拜托,我是黄瓜的初学者,我想解决这个问题。如果可以,请你帮助我。

回答by Thomas Sundberg

Your exception tells me that you are missing a dependency.

您的异常告诉我您缺少依赖项。

I would clone https://github.com/cucumber/cucumber-java-skeletonor download it as a zip and get it up and running. This would hopefully tell what's wrong with your setup.

我会克隆https://github.com/cucumber/cucumber-java-skeleton或将其下载为 zip 文件并启动并运行。这有望说明您的设置有什么问题。

回答by Amila Sampath

This problem is happening because of missing of the encoding inside of gherkin in your eclipse set up. You have to install the latest version of gherkin. The latest available gherkin can be find from Marven repository. After downloading the latest version, import that gherkin jar file to the cucumber project.

发生此问题是因为您的 eclipse 设置中缺少小黄瓜内部的编码。您必须安装最新版本的小黄瓜。最新可用的小黄瓜可以从 Marven 存储库中找到。下载最新版本后,将该小黄瓜 jar 文件导入到 Cucumber 项目中。

回答by Himadri

Please add cucumber tags which starts with @ symbol Like below

请添加以@符号开头的黄瓜标签,如下所示

@featureTest
Feature: Prove the concept of my script

@Scenario1
  Scenario: My first Test
    Given This is my first step
    When This is my second step
    Then This is my third step

Make sure the words in feature file matches "As is" in Step definition java file for Given, When and Then

确保特征文件中的单词与 Given、When 和 Then 的 Step 定义 java 文件中的“原样”匹配