cucumber - 在 CucumberJs 和 Cypress 中是否可以使上下文独立并允许具有相同描述的步骤?
问题描述
我有一个基于 typescript 的 Cypress 和 CucumberJs 设置,用于我正在处理的项目中的端到端测试。
它恰好有两个不同的功能文件bus.feature
,car.feature
以及它们的步骤定义文件bus.spec.ts
和car.spec.ts
我有两个不同的步骤定义:
Then(
'I {string} the Destination page', (operation: operation) => {
cy.location().should(location => {
switch (operation) {
case 'visit':
expect(location.pathname).to.eq('/e2e/destination')
break
case `can't visit`:
expect(location.pathname).to.eq('/e2e/bus')
break
}
})
}
)
和
Then(
'I {string} the Destination page', (operation: operation) => {
cy.location().should(location => {
switch (operation) {
case 'visit':
expect(location.pathname).to.eq('/e2e/destination')
break
case `can't visit`:
expect(location.pathname).to.eq('/e2e/car')
break
}
})
}
)
它们的识别字符串相同,'I {string} the Destination page'
但在实现上略有不同(例如 case can't visit
)。
当我运行测试时,bus
它完全完美地执行。
一个有一个问题,car
因为两个测试的识别字符串相同,Cypress+CucumberJs 套件只检测第一个bus
定义,忽略car
和正确的定义。
我明白为什么,第一个被检测到,就是这样。问题是,有没有办法分离不同文件的上下文,所以能够有相同的定义名称和不同的实现?
提前致谢
解决方案
为什么不
'I {string} the Destination page for {string}', (operation: operation, transportMode) => {
...
expect(location.pathname).to.eq(`/e2e/car${transportMode}`)
或者这会破坏特征和步骤之间的匹配吗?
推荐阅读
- c# - 内核对象和WaitHandle有什么关系?
- android - 测试类在 android 上不能正常工作?
- r - 如何在 r 上显示 Q1 到没有年份的季度
- python-3.x - 无法在 python 中导入 sentence_transformers
- python - Tensoflow tf.data.Dataset.from_tensor_slices 无法生成适合线性模型的简单数据集
- jwt - APNS 如何确定提供者令牌的年龄?
- html - 从本地文件将 Uicon 添加到 Shiny
- d3.js - d3.js - 选择强制布局组不更新节点
- flutter - 在 MaterialApp 中嵌套多个包构建器
- json - 通过 Web 表单请求向 Jenkins 添加 SSH 凭据