Cucumber&Protractor Feature文件语法错误求助:Unexpected token, expected ;
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

