在“步骤2”中执行“步骤1” - 柏树+黄瓜

问题描述 投票:0回答:2

我在步骤中遇到了许多类似的代码片段,在“更大”的步骤中重复使用步骤可以解决问题。是否可以在步骤 2 中运行步骤 1?

And('My Step 1', () => {
  some code;
});

And('My Step 2', () => {
  can I execute 'My Step 1' here?
  code;
});
cucumber cypress bdd cypress-cucumber-preprocessor
2个回答
4
投票

您可以在命令文件中添加步骤,然后在测试中调用它们。 您的命令将如下所示:

Cypress.Commands.add("Step1", function () {
  Do stuff here
});

然后在测试中您可以重复使用这些命令,如下所示:

it('My Step 2', () => {
  cy.Step1();
  code;
});

记得在你的index.js中导入命令文件


0
投票

提供的解决方案可能是可用的最佳答案,但肯定不是理想的答案。我们需要一个可以从另一个 Cucumber 步骤调用现有 Cucumber 步骤的方法,而无需向命令添加函数。

© www.soinside.com 2019 - 2024. All rights reserved.