I have 2 similar tests within the same feature
file. They are essentially the same test except one expects to find a list of data while the other expects no data.
They both share identical step names, however the implementations of the final step is different.
myfeature.feature
Scenario Outline: Log in and see data
Given User visits page
When User logs in
Then Should see expected result // Same name step
Scenario Outline: Log in and no data
Given User visits page
When User logs in
Then Should see expected result // Same name step
The test definition file looks something like:
describe('Log in and see data', () => {
Given('User visits page', () => {
// Do page visit
});
When('User logs in', () => {
// Perform log in logic
});
Then('Should see expected result', () => {
cy.get('my-component').should('be.visible');
});
});
describe('Log in and no data', () => {
Given('User visits page', () => {
// Do page visit
});
When('User logs in', () => {
// Perform log in logic
});
Then('Should see expected result', () => {
cy.get('my-component').should('not.exist');
});
});
When I am running Cypress it shows that the first test passes correctly, however the second test fails and when I look into the test run it seems that the Should see expected result
step is hitting the Then
definition from the top describe
block for the other test…
Questions around the behaviour seen:
- Is there any reason for this?
- Is there a way in which I can stop this from happening and the test hit the correct definition?
- What is the best practise here?