Java 如何解决运行时.cucumberexception 的错误解析功能文件

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

How to resolve runtime.cucumberexception for error parsing feature file

javawebdrivercucumberbdd

提问by SKumar

I just created simple java file which is used to execute the feature file through cucumber, but Its failed, and throws following run time exception

我刚刚创建了一个简单的java文件,用于通过黄瓜执行特征文件,但它失败了,并抛出以下运行时异常

Exception in thread "main" cucumber.runtime.CucumberException: Error parsing feature file C:/Users/XXX/XXXX/src/test/java/RunTest.java
    at cucumber.runtime.FeatureBuilder.parse(FeatureBuilder.java:133)
    at cucumber.runtime.model.CucumberFeature.loadFromFeaturePath(CucumberFeature.java:102)
    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:201)
    at cucumber.runtime.Runtime.run(Runtime.java:109)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: gherkin.lexer.LexingError: Lexing error on line 1: 'package test.java;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

    @CucumberOptions(features="src/test/resources/")
    public class RunTest extends AbstractTestNGCucumberTests {
    }

Feature file:

特征文件:

Feature: Search India on BBC website and verify search.

@Search
  Scenario Outline: Search India on BBC website and verify it.
    Given I open the firefox browser
    And I navigating to BBc website
    Then I click at search textbox
    And I enter "India" in search textbox
    And I click at Search button
    Then I should be taken to search page
    And I verify India on search page

Can somebody tell me how to resolve this issue?

有人可以告诉我如何解决这个问题吗?

采纳答案by Tyler MacMillan

When using a Scenario Outline, you need to provide an "Examples" section. In this case, it looks like you don't need a scenario outline at all, so:

使用场景大纲时,您需要提供“示例”部分。在这种情况下,您似乎根本不需要场景大纲,因此:

Feature: Search India on BBC website and verify search.

  @Search
  Scenario: Search India on BBC website and verify it.
    Given I open the firefox browser
    And I navigating to BBc website
    Then I click at search textbox
    And I enter "India" in search textbox
    And I click at Search button
    Then I should be taken to search page
    And I verify India on search page

If you do need a scenario outline, you want something like:

如果您确实需要场景大纲,则需要以下内容:

Feature: Search India on BBC website and verify search.

  @Search
  Scenario Outline: Search India on BBC website and verify it.
    Given I open the firefox browser
    And I navigating to BBc website
    Then I click at search textbox
    And I enter "<country>" in search textbox
    And I click at Search button
    Then I should be taken to search page
    And I verify <country> on search page

  Examples:
    | country |
    | India   |
    | China   |

回答by Anmol Naik

I have identified this issue where i had extra space before colon in Feature file or in Scenario.

我已经确定了这个问题,我在功能文件或场景中的冒号前有额外的空间。

So issue should be resolved after removing extra spaces.

所以问题应该在删除多余的空格后解决。

Previous

以前的

    Scenario Outline: Search India on BBC website and verify it.

Expected

预期的

    ScenarioOutline: Search India on BBC website and verify it.

回答by user1485084

This was really useful.. I had the same error and after removing the space between the text Scenario and Colon. it would be useful if IDEshows the error to correct it ?? Scenario: and no colon after Given Just to let you know. Scenario Outline: Login with correct username and password Given I navigate to Login Page And I enter < username > and < password > And I click login button Then I should see the userform Page

这真的很有用。我有同样的错误,在删除文本场景和冒号之间的空格后。如果 IDE 显示错误来纠正它会很有用吗??场景:并且在 Given 之后没有冒号只是为了让您知道。场景大纲:使用正确的用户名和密码登录给定我导航到登录页面,然后输入<用户名>和<密码>,然后单击登录按钮然后我应该看到用户表单页面

Examples:
  | username                   | password  |

  | apple                      | passapple |
  | ball                       | passball  |
  | cat                        | passcat   |

回答by Afsar Ali

I had similar issue .After removing the space between (:) semi colon and Feature, Scenario ,Scenario-outline etc.. My error resolved .

我有类似的问题。删除 (:) 分号和功能、场景、场景大纲等之间的空格后。我的错误解决了。

e.g :

例如:

Feature: Call all APIs Incidents, Services
     Scenario: Create POST call and verify data 
         Given user_has_a_list_of_products
         When we_can_get_a_list_of_product_details

and ,

和 ,

    Feature: Call all APIs Incidents, Services
     Scenario Outline: Create POST call and verify data 
         Given user_has_a_list_of_products <usertype>
         When we_can_get_a_list_of_product_details

        Examples:
            | usertype     |
            | Domestic     |

回答by skb

Consider the below scenario -

考虑以下场景 -

Feature: Booking Confirmation Page Scenario: Verify the Page components Given that a customer is on the "BookingConfirmation" page When the customer views the Page Then they should be able to view the following : | Header | BookingId | Passengers name | Date of travel | Time of travel | |Bus details | Total amount paid |Destination name|Destination Image| |Time to reach destination | Footer|

Feature: Booking Confirmation Page Scenario: Verify the Page components Given that a customer is on the "BookingConfirmation" page When the customer views the Page Then they should be able to view the following : | Header | BookingId | Passengers name | Date of travel | Time of travel | |Bus details | Total amount paid |Destination name|Destination Image| |Time to reach destination | Footer|

If you specify the values to verify in 2nd line as shown it will give a parse error. When you copy the above and paste in the editor it will not show you any error. But when you run it it will give the parse error. So we need to specify the value to verify in a single line even if it doesn't fit in the editor

如果您在第二行中指定要验证的值,如图所示,它将给出解析错误。当您复制上述内容并粘贴到编辑器中时,它不会显示任何错误。但是当你运行它时,它会给出解析错误。所以我们需要在一行中指定要验证的值,即使它不适合编辑器

So the scenario will be as below

所以场景如下

Scenario: Verify the Page components Given that a customer is on the "BookingConfirmation" page When the customer views the Page Then they should be able to view the following : | Header | BookingId | Passengers name | Date of travel | Time of travel | Bus details | Total amount paid |Destination name|Destination Image|Time to reach destination |Footer|

Scenario: Verify the Page components Given that a customer is on the "BookingConfirmation" page When the customer views the Page Then they should be able to view the following : | Header | BookingId | Passengers name | Date of travel | Time of travel | Bus details | Total amount paid |Destination name|Destination Image|Time to reach destination |Footer|

回答by Adrian Jimenez

make sure you only have word Feature once

确保你只有一次 Feature