赛普拉斯黄瓜^ ParseError:意外令牌

时间:2019-11-11 12:09:00

标签: javascript automated-tests cucumber cypress

尝试在Chrome和Electron浏览器中运行我的测试时,似乎出现以下异常:

cypress-auto-framework\cypress\integration\Cucumber\EATest.feature:2
    Test the EA Features
         ^
ParseError: Unexpected token

我的特征文件用于捕获需求:

Feature: EaTestFeature
    Test the EA Features

    Scenario: Test the login feature
        Given I visit the EA site
        And I click on the login link
        And I login using credentials "admin" and "Password"

“我的步骤”文件用于通过实际操作映射我的功能文件:

import {Given, When, And, Then} from "cypress-cucumber-preprocessor/steps"
/// <reference types="Cypress" />

Given('/^I visit the EA site$/', () => {
    cy.visit('http://eaapp.somee.com/')
})

And('/^I click on the login link$/', () => {
    cy.contains('Login').click();
})

And('/^I login using credentials {string} and {string}$/', (userName, password) => {
    cy.get('#UserName').type(userName)
    cy.get('#Password').type(password)
    cy.get('.btn').click();
})

插件> index.js文件:

module.exports = (on, config) => {
  const cucumber = require('cypress-cucumber-preprocessor').default

  module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
  }
}

Package.json文件:

    {
  "name": "cypress-auto-framework",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^3.6.1",
    "cypress-cucumber-preprocessor": "^1.16.2",
    "cypress-dark": "^1.7.14",
    "cypress-xpath": "^1.4.0"
  },
  "dependencies": {},
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
}

任何想法可能是什么问题?

谢谢

2 个答案:

答案 0 :(得分:0)

似乎您正在混合使用正则表达式步骤和纯字符串类型的占位符。
您有2种可能的选择:

  1. 用正则表达式写定义:And(/^I login using credentials "(.*?)" and "(.*?)"$/, ...
  2. 将定义写为带有占位符类型的字符串:And('I login using credentials {string} and {string}',...

答案 1 :(得分:0)

我想原因是您将黄瓜插件放在错误的index.js文件中,它应该在插件> index.js中,而不是在> index.js中