You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

单Feature文件多Feature节点触发FeatureParserException报错排查

问题描述

在单个.feature文件中编写两个Feature节点(Onboard User和SignUp User)后,运行测试触发io.cucumber.core.gherkin.FeatureParserException错误,提示解析资源失败;将两个Feature拆分到独立文件时则运行正常。

相关Feature代码

Feature:Onboard User
    Scenario:Test whether Onboarding is successful
        Given User is on apploaded page
        When user clicks nextbutton link,navigates to upcoming onboard pages
        And Once all the onboard screens get over,loads the login page
        Then User successfully completes onboard screens

Feature: SignUp User
    Background: User is on Login page
    Scenario Outline: Test whether SignUp is successful
        Given Signup link Visibility
        When User clicks Signup link which navigates to SignUp page
        And Update <firstname>,<lastname>,<email>,<password>,<confirm password>,<phone number>and submit
        Then User successfully completes Signup and navigtes to SignIn page
        Examples:
            | firstname | lastname | email                      | password  | confirm password |
            | dona      | feble    | donafeble@gmail.com        | 123456    | 123456           |
            | riya      | mary     | riyamaryemmanuel@gmail.com | test@riya | test@riya        |

报错信息

[ERROR] initializationError(Runner.AppTest)  Time elapsed: 0.004 s  <<< ERROR!
io.cucumber.core.gherkin.FeatureParserException:
Failed to parse resource at: file:///e:/LMS-cucumber-appium/src/test/resources/features/home.feature
(8:1): expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ExamplesLine, #ScenarioLine, #RuleLine, #Comment, #Empty, got 'Feature: SignUp User'
(9:5): expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ExamplesLine, #ScenarioLine, #RuleLine, #Comment, #Empty, got 'Background: User is on Login page'.
问题原因及解决办法
  • 原因:Cucumber遵循的Gherkin语法规范明确要求,单个.feature文件只能包含一个Feature节点。解析器处理完第一个Feature的内容后,会预期文件结束或该Feature下的合法元素(如场景、规则、注释等),此时出现第二个Feature声明属于语法违规,因此抛出解析异常。
  • 解决办法:将两个Feature拆分到独立的.feature文件中:
    1. 创建onboard_user.feature,将Feature: Onboard User及其下属的场景代码移入该文件
    2. 创建signup_user.feature,将Feature: SignUp User及其下属的Background、Scenario Outline等代码移入该文件

内容的提问来源于stack exchange,提问作者Dona feble p j

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 06:48:29