cucumber - 在'step 2'中执行'step 1' - cypress+cucumber
问题描述
我在步骤中遇到了许多类似的代码,在“更大”步骤中重复使用步骤可以解决问题。是否可以在步骤 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 中导入命令文件
推荐阅读
- mysql - 使用 TypeORM 插入数组时,作为结果出来的 id 的顺序?
- javascript - 做... while 语句
- generics - 在 Fortran 中使用子模块进行通用分配
- typescript - 是否可以从 Typescript 字符串联合创建对象?
- discord - Discord 自定义表情符号在 DISCORD.PY 中为其提供变量时显示错误
- sql - Postgres:如何在where语句中指定参数
- java - 当值匹配条件时终止流,否则收集到集合中
- tensorflow - 使用导入 tensorflow 集线器时出错
- kubernetes - Ingress Controller 无法连接到外部
- mysql - MySQL查询中的JSON数据搜索