I've a Cypress and CucumberJs setup based on typescript for end to end tests in a project I'm working on.
It happens to have two different feature files bus.feature
and car.feature
with their step definition files bus.spec.ts
and car.spec.ts
I've two different step definitions:
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
}
})
}
)
and
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
}
})
}
)
identical in their recognitional string 'I {string} the Destination page'
but slightly different in the implementation (for instance the case can't visit
).
When I run the tests, the bus
one is fully executed perfectly.
The car
one has an issue because, being the recognitional string the same for both tests, the Cypress+CucumberJs suite detect just the first bus
definition, ignoring the car
and proper one.
I understand why, the first one is detected and that's it. Question is, is there a way to separate contexts of different files, so being able to have also same definition name with different implementation?
Thanks in advance
Why not
'I {string} the Destination page for {string}', (operation: operation, transportMode) => {
...
expect(location.pathname).to.eq(`/e2e/car${transportMode}`)
or does that mess up the matching between feature and step?