【问题标题】:Execute 'step 1' inside 'step 2' - cypress+cucumber在'step 2'中执行'step 1' - cypress+cucumber
【发布时间】:2021-09-07 09:31:01
【问题描述】:
我在步骤中遇到了许多类似的代码,在“更大”步骤中重复使用步骤可以解决问题。是否可以在步骤 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
【解决方案1】:
您可以在命令文件中添加步骤,然后在测试中调用它们。
您的命令将如下所示:
Cypress.Commands.add("Step1", function () {
Do stuff here
});
然后在您的测试中,您可以像这样重用这些命令:
it('My Step 2', () => {
cy.Step1();
code;
});
记得在你的 index.js 中导入命令文件