Cypress.io 和 Cucumber.io 测试集成,缺少步骤实现:

IT技术 reactjs cucumber cypress
2021-05-02 04:46:30

Cypress 和 Cucumber 的集成似乎进展顺利,但是在执行测试时出现以下错误:

Step implementation missing for: I open login page

cypress.json

{
  "video": false,
  "baseUrl": "http://localhost:8080",
  "testFiles": "**/*.feature",
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true
  }
}

./cypress/integration/login.feature

Feature: Login Feature

  I want to login

  @focus
  Scenario: Navigate to Login
    Given I open login page
    Then I see Login

./cypress/integration/Login/login.js

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

Given( 'I open login page', () => cy.visit( '/Login' ) );

Then( 'Login page should be shown', () => cy.url().should( 'include', '/Login' ) );
3个回答

您的cypress-cucumber-preprocessor配置应该在package.json 中,而不是在cypress.json 中

另外,我相信步骤实现文件夹名称必须与功能文件名匹配。所以你应该将你的步骤实现文件夹重命名为login而不是 Login ( ./cypress/integration/login/login.js)

在此处查看文档

在您的自定义路径中添加step_defintionspackage.json

"cypress-cucumber-preprocessor": {
   "step_definitions": "cypress/integration/features/step_definitions/**/"
}

虽然我不认为这个答案是理想的,但我设法通过"cypress-cucumber-preprocessor"从 cypress.json 中删除并将子目录从“cypress/integration”目录移动到“cypress/support/step_definitions”来解决问题