javascript - 如何创建一个通用步骤定义文件夹以供 cypress/cucumber 中的所有 .feature 文件使用?
问题描述
我有一个在柏树(javascript)之上使用黄瓜构建的框架。
我正在使用这个版本:cypress-cucumber-preprocessor: ^4.0.1
根据文档(由行为确认),cucumber 必须有一个与功能文件同级且名称相同的文件夹,因此 cucumber 知道在哪里查找步骤。因此,我的文件结构是:
-integration
---myApp
-----users
-------login.feature
-------login
---------login.steps.js
-------signup.feature
-------signup
---------signup.steps.js
-----someotherentity
-------foo.feature
-------foo
---------foo.steps.js
所以 login.feature 需要一个名为“login”的文件夹,我在其中存储步骤定义等。
例如,所有这些功能文件都需要这两个步骤
Given('I visit the homepage', () => {cy.visit('https://myhomepage.com)})
When('I click Ok', () =>{cy.get('#proceedButton').click()})
我在所有 3 个文件中都定义了这 2 个步骤,因此为有关导航、点击等的常见步骤定义创建一个通用文件夹是有意义的。
我怎么能在这里做到这一点?
解决方案
请看这里:
https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#cypress-configuration
如果您决定更改 Cypress Cucumber Preprocessor Style 模式,您必须注意 package.json 文件中的相应信息
例如:“cypress-cucumber-preprocessor”:{“commonPath”:“common”,“stepDefinitions”:“step_definitions”}
允许您为常用步骤定义创建一个单独的文件夹