首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cypress Cucumber ^ ParseError:意外的标记

Cypress Cucumber ^ ParseError:意外的标记
EN

Stack Overflow用户
提问于 2019-11-11 20:09:01
回答 3查看 1.8K关注 0票数 3

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

代码语言:javascript
复制
cypress-auto-framework\cypress\integration\Cucumber\EATest.feature:2
    Test the EA Features
         ^
ParseError: Unexpected token

我的功能文件用于捕获需求:

代码语言:javascript
复制
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"

我的Steps文件用于将我的功能文件映射到实际操作:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
module.exports = (on, config) => {
  const cucumber = require('cypress-cucumber-preprocessor').default

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

Package.json文件:

代码语言:javascript
复制
    {
  "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
  }
}

你知道问题是什么吗?

谢谢

EN

回答 3

Stack Overflow用户

发布于 2019-11-12 18:43:08

看起来你混合了regex步骤和纯字符串类型的占位符。

您有两种可能的选择:

使用正则表达式:And(/^I login using credentials "(.*?)" and "(.*?)"$/, ...

  • Write定义为带有类型占位符的字符串:And('I login using credentials {string} and {string}',...

  1. 写入定义
票数 0
EN

Stack Overflow用户

发布于 2019-11-28 02:03:49

我猜原因是你把黄瓜插件放到了错误的index.js文件中,它应该在插件> index.js,而不是支持> index.js中

票数 0
EN

Stack Overflow用户

发布于 2020-01-07 07:27:51

尝试在config块之外声明cucumber常量

代码语言:javascript
复制
const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
  module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58801072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档