改进赛普拉斯结构并重用多个文件中的给定步骤

Improve Cypress structure and reuse Given step in multiple files

我正在使用 Cypress 和 Cucumber 进行端到端测试。

我有以下赛普拉斯结构:

page-one/
another-page/
cypress/integration/page-one/check-hero.js
cypress/integration/page-one/check-custom-block.js
cypress/integration/page-one.feature
cypress/integration/another-page.feature

在文件 check-hero.jscheck-custom-block.js 中我有:

Given('I navigate to page one', () => {
  cy.visit(`${Cypress.env('baseUrl')}/page-one`);
});

我能否改进此结构以使其更 DRY 并在多个文件中重用此 Given 步骤?

您可以创建可重复使用的步骤定义,正如他们在 cypress-cucumber-preprocessor 的官方文档中所称的那样。

您可以使用 Given 步骤在 cypress/integration/common/ 中创建一个文件,然后在 cypress/integration/page-one/check-hero.jscypress/integration/page-one/check-custom-block.js 中使用它。如果我很好地理解文档,那么具有可重用步骤的文件实际上可以有任何名称,比如在您的示例中 visit.js

请使用 Cypress Commands 重新使用 link