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

Cucumber&Protractor Feature文件语法错误求助:Unexpected token, expected ;

Fixing the SyntaxError in Your Cucumber/Protractor Setup

Hey there! Let's break down why you're running into this error and how to fix it. That SyntaxError is popping up because Protractor is mistakenly treating your .feature file as a JavaScript file—the babylon parser mentioned in the error is for JS, so it can't understand Gherkin's syntax at all. Here's what you need to do:

1. Fix Your protractor.conf.js Configuration

This is the root cause. You probably have your .feature file listed in the specs array (which is meant for JavaScript test files) or haven't properly configured the Cucumber framework. Here's a corrected configuration example:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  // Tell Protractor to use the Cucumber framework
  framework: 'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  // Leave specs empty—we'll specify feature files separately
  specs: [],
  // Point to your .feature files
  features: ['./features/**/*.feature'],
  cucumberOpts: {
    // Path to your step definition JavaScript files
    require: ['./step_definitions/**/*.js'],
    // Optional: Add formatting for readable output
    format: 'pretty'
  },
  capabilities: {
    browserName: 'chrome'
  }
};

2. Clean Up Your Feature File (For Better Gherkin Compliance)

Your feature file is almost right, but adding indentation to the description and scenario steps will make it more readable and aligned with Gherkin best practices:

Feature: Verify the login page as UK customer
  As I am a UK customer
  I want to open the login page
  So that I can see the login page content and go to my-cart page

  Scenario: Verify the login page submit functionality as a UK registered customer
    Given I am a UK customer
    When I see the submit-button
    And I filled all the mandatory fields
    Then I am able to click on it to login
    And I am able to open MyCart page

3. Double-Check Your Dependencies

Make sure you have all the required packages installed in your project:

npm install protractor cucumber protractor-cucumber-framework --save-dev

Once you update your configuration and fix up the feature file, run Protractor again—it should now properly parse your Gherkin feature file instead of treating it like JS.

内容的提问来源于stack exchange,提问作者Spicchio

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:27:30