我有一个基于 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
和正确的定义。
我明白为什么,第一个被检测到,就是这样。问题是,有没有办法分离不同文件的上下文,所以能够有相同的定义名称和不同的实现?
提前致谢