如何解决 runtime.cucumberexception 错误解析功能文件

How to resolve runtime.cucumberexception for error parsing feature file

我刚刚创建了简单的 java 文件,用于通过 Cucumber 执行功能文件,但它失败了,并抛出以下 运行 时间异常

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

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

使用场景大纲时,您需要提供一个 "Examples" 部分。在这种情况下,看起来你根本不需要场景大纲,所以:

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

如果你确实需要场景大纲,你需要这样的东西:

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   |

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

Examples:
  | username                   | password  |

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

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

例如:

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

并且,

    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     |

考虑以下场景 -

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|

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

所以场景如下

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|

确保你只有一次特征词

我也遇到了这个问题。就我而言,我错过了一个管道'|'在我的一个数据中 table。添加后,问题解决。数据 table(或示例中的某个时间)

Issue:
      | feed.title            |
      | feed.updated          
      | feed.author.name      |

Corrected(added pipe in 2nd data) as:
      | feed.title            |
      | feed.updated          |
      | feed.author.name      |

我收到了同样的错误消息,然后我意识到有人使用 // 向小黄瓜步骤添加了注释。它应该使用 #

问题是您使用的是“场景大纲”而不是“场景”。所以你只需要删除“大纲”就可以了。

@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

但是如果你想针对多个输入执行相同的场景而不是选择正确的东西,即“场景大纲:”只需要在其中添加示例,如:

@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" |
    | "UK"    |