'Cypress - exclude tests from beforeEach
90% of my tests need to do one task before start so I made beforeEach function that works perfect.
Rest 10% need to do something else before start.
Is in Cypress some way to do beforeEach except some tests?
Solution 1:[1]
As of cypress version 8.2.0 and above, you can use the Cypress.currentTest object to check which test is running every time.
describe('describe 1', () => {
beforeEach(() => {
switch(Cypress.currentTest.title) {
case 'test 3 - i am not so usual':
// case 'test 4 - not so usual too': (or any other test title)
cy.yourCustomCommand()
// or let your special test to take control...below
break;
default:
// do as usual
cy.yourStandardCommand()
break;
}
})
it('usual test 1', () => {})
it('usual test 2', () => {})
it('test 3 - i am not so usual', () => {
cy.letMeDoMyStaff()
// ...
})
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris Harris |
