【问题标题】:CucumberJs : unable to find step definition fileCucumberJs:找不到步骤定义文件
【发布时间】:2021-01-07 09:24:36
【问题描述】:

当我尝试运行 cypress 时,它会检测到功能文件,但无法获取步骤定义文件,下面是我看到的错误。

在我的配置下分享:

  1. 打包json文件sn-p
{...
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
  }
}
  1. cypress.json
{
   ...
   "testFiles": "**/*.{feature,features}"
}
  1. plugins/index.js
const cucumber = require('cypress-cucumber-preprocessor').default
 
module.exports = (on, config) => {
  on('file:preprocessor', cucumber())
}

还分享我的测试文件:

功能文件(google/check-title.feature)

Feature: The Google

  I want to open google page
  
  @focus
  Scenario: Opening a social network page
    Given I open Google page
    Then I see "Google" in the title

步骤定义文件 (google/check-title/check-title.js)

import { Given, Then } from 'cypress-cucumber-preprocessor/steps';

const url = 'https://google.com';
Given('I open Google page', () => {
  cy.visit(url);
});
Then(`I see {string} in the title`, (title) => {
  cy.title().should('include', title);
});

【问题讨论】:

  • 你解决过这个问题吗?

标签: javascript reactjs angular cypress cucumberjs


【解决方案1】:

这可能会有所帮助: 在 package.json 中将标志 nonGlobalStepDefinitions 设置为 false,并定义测试来自的目录:“stepDefinitions”:“cypress/integration/”

{
  "devDependencies": {
    "cypress": "^9.1.0",
    "cypress-cucumber-preprocessor": "^4.3.0"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": false,
    "stepDefinitions": "cypress/integration/"
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 1970-01-01
    相关资源
    最近更新 更多