在 'step 2' 中执行 'step 1' - cypress+cucumber

Execute 'step 1' inside 'step 2' - cypress+cucumber

我在我的步骤中遇到了很多类似的代码片段,重新使用 'bigger' 步骤中的步骤可以解决问题。是否可以在步骤 2 中 运行 步骤 1?

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

And('My Step 2', () => {
  can I execute 'My Step 1' here?
  code;
});

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

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

然后在您的测试中,您可以像这样重用这些命令:

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

记得在你的 index.js

中导入命令文件