Cucumber.js
对使用和Cypress
某些步骤定义
的最佳实践有一些疑问。
基本上,测试需要一个可以相同实现的状态和结果:
这是一个状态的例子:
Given(
'the {int} item of the {string} component is visible',
(index, ComponentIndex, mapper: ComponentMapper) => {
cy.get('[data-test^="cmp-"]').eq(cmpMap[mapper]).as(mapper)
cy.get(`@${mapper}`)
.find('.component__item')
.eq(index)
.should('be.visible')
}
)
这是一个结果的例子:
Then(
'the {int} item of the {string} component is visible',
(index, ComponentIndex, mapper: ComponentMapper) => {
cy.get('[data-test^="cmp-"]').eq(cmpMap[mapper]).as(mapper)
cy.get(`@${mapper}`)
.find('.component__item')
.eq(index)
.should('be.visible')
}
)
在这种情况下,我只看到代码重复,因为Given
和Then
实现相同的代码,执行相同的检查。我想了解所有可能的解决方案,以最有效的方式实现这一点。
双重实施
保留描述中定义的双步骤
PRO:更清晰的
缺点:双代码\
单一实现
留下一个实现,在Given
或 中Then
,因为 cucumber 实际上并没有检查特征文件中的 Step 和定义文件中与 step 相关的函数的匹配
PRO:代码的单一实现
缺点:不太清楚,更混乱在步骤定义中
外部功能
创建一个函数以放入例如 Cypress 的某些命令或 utils 中,并在两个定义中使用它
PRO:单一实现
缺点:过度设计?在 Cucumber.js 中从未见过这种方法
检查所有这些,您会建议哪一个?谢谢