如何解决解析功能文件时出错的runtime.cucumberexception
Posted
技术标签:
【中文标题】如何解决解析功能文件时出错的runtime.cucumberexception【英文标题】:How to resolve runtime.cucumberexception for error parsing feature file 【发布时间】:2015-11-21 15:01:55 【问题描述】:我刚刚创建了一个简单的 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
谁能告诉我如何解决这个问题?
【问题讨论】:
【参考方案1】:使用场景大纲时,您需要提供“示例”部分。在这种情况下,您似乎根本不需要场景大纲,所以:
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 |
【讨论】:
【参考方案2】:这真的很有用..我有同样的错误,删除文本场景和冒号之间的空格后。如果IDE显示错误来纠正它会很有用?? 设想: Given 之后没有冒号,只是为了让您知道。 场景大纲:使用正确的用户名和密码登录 鉴于我导航到登录页面 我输入和 然后我点击登录按钮 然后我应该看到用户表单页面
Examples:
| username | password |
| apple | passapple |
| ball | passball |
| cat | passcat |
【讨论】:
【参考方案3】:我有类似的问题。删除 (:) 分号和 Feature、Scenario 、Scenario-outline 等之间的空格后。我的错误解决了。
例如:
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 |
【讨论】:
【参考方案4】:考虑以下场景 -
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|
【讨论】:
【参考方案5】:确保您只有一次单词 Feature
【讨论】:
【参考方案6】:我也遇到过这个问题。就我而言,我错过了一个管道'|'在我的一个数据表中。添加后,问题解决。数据表(或示例中的某个时间)
Issue:
| feed.title |
| feed.updated
| feed.author.name |
Corrected(added pipe in 2nd data) as:
| feed.title |
| feed.updated |
| feed.author.name |
【讨论】:
【参考方案7】:我收到了同样的错误消息,然后我意识到有人使用 //
在小黄瓜步骤中添加了评论。它应该使用#
【讨论】:
【参考方案8】:问题是您使用了“场景大纲”而不是“场景”。所以你只需要删除“大纲”就可以了。
@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" |
【讨论】:
以上是关于如何解决解析功能文件时出错的runtime.cucumberexception的主要内容,如果未能解决你的问题,请参考以下文章
在登录功能上使用 FireBase 进行 Google 登录时出错。无法解析“对象”中的方法“getSignInIntent”