0

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

在此处输入图像描述

在我的配置下分享:

  1. 打包 json 文件片段
{...
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
  }
}
  1. 柏树.json
{
   ...
   "testFiles": "**/*.{feature,features}"
}
  1. 插件/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);
});

4

1 回答 1

0

这可能会有所帮助:在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/"
  }
}

于 2021-12-04T00:36:29.927 回答