在 cypress-cumber-preprocessor 中遇到“缺少步骤实现”问题(cypress 版本 - 13.1.0 和 cucumber 预处理器 - 4.3.1)

Getting "Step implementation missing" issue in cypress-cumber-preprocessor (cypress version - 13.1.0 and cucumber preprocessor - 4.3.1)

提问人:sudeep mahato 提问时间:9/29/2023 最后编辑:sudeep mahato 更新时间:9/29/2023 访问量:70

问:

我已经使用以下方法安装了 cucumber 预处理器:- npm install --save-dev cypress-cucumber-preprocessor。

赛普拉斯版本:- 13.1.0 Cucumber 预处理器版本:- 4.3.1

下面是我的文件夹结构:-

cypress.config.js

const cucumber = require('cypress-cucumber-preprocessor').default
const { defineConfig } = require("cypress")

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
      on('file:preprocessor', cucumber())
    },
    specPattern: "cypress/e2e/*.feature",
  },
});

package.json

{
  "name": "cypress_cucumber_bdd",
  "version": "2.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "cypress open"
  },
  "author": "sudeep mahato",
  "license": "ISC",
  "devDependencies": {
    "cypress": "^13.1.0",
    "cypress-iframe": "^1.0.1"
  },
  "chromeWebSecurity": false,
  "dependencies": {
    "axios": "^1.5.0",
    "cypress-cucumber-preprocessor": "^4.3.1"
  },
  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": false,
    "step-definations": "cypress/e2e/hubspot",
    "cucumberJson": {
      "generate": "true",
      "outputFolder": "cypress/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
  }
  }
}

hubspot.功能

Feature: Hubspot user interaction

want to see the demo

    Scenario: User should be able to browse the application
    Given context
    When event
    Then outcome



  hubspotSteps.js

import { Given, When, Then, And } from "cypress-cucumber-preprocessor/steps";
            
            Given("context", ()=>{
                cy.visit('https://www.hubspot.com');
            });
            
            When("event", ()=>{
                cy.get('#hs-eu-confirmation-button').click();
            });
            
            Then("outcome", ()=>{
                cy.get('.hsg-nav__link').eq(3).click();
            });

配置文件和文件夹程序

JSON 文件

功能文件

步骤

错误

javascript 黄瓜 cypress cypress-cucumber-preprocessor

评论

0赞 J.Ollie.Rogers 9/29/2023
请考虑将屏幕更改为文本,以便更轻松地解决您的问题。
0赞 sudeep mahato 9/29/2023
确定。再次发布带有详细说明的相同查询。谢谢

答:

0赞 Aladin Spaz 9/29/2023 #1

步骤定义匹配的一般模式是

{
  "stepDefinitions": [
    "cypress/e2e/[filepath]/**/*.{js,ts}",
    "cypress/e2e/[filepath].{js,ts}",
    "cypress/support/step_definitions/**/*.{js,ts}",
  ]
}

功能文件名的一部分将被替换到占位符所在的模式中。hubspot[filepath]

您可以更改模式,但它应该在您的案例中包含扩展,并且通配符在获得更大的测试套件时更容易。js

评论

0赞 sudeep mahato 9/30/2023
这现在实际上正在工作。我正在尝试更多地了解我的文件夹结构的“扩展 js”,以及为什么它很重要。你能@Aladin斯帕兹详细说明一下吗?再次感谢您的解决方案。
0赞 Aladin Spaz 10/1/2023
是的,文档说它正在使用 cosmiconfig 来使用您给出的模式,还有一个指向额外阅读的链接。