Hooks Are Not Run if Defined in Cypress/support/
See original GitHub issueCurrent behavior
It’s mentioned here that Cypress/support/index.js is a good place to set reusable hooks, but if I define a Cucumber hook in this file they are never run. Mocha hooks DO run, but I need to use tags so I want to use the Cucumber hooks if possible. Is there a specific reason the Cucumber hooks aren’t being run when placed in the support directory but mocha hooks are?
Desired behavior
Cucumber hooks run when placed/imported into the Cypress/support/index.js file.
Test code to reproduce
Just use the Cypress example repo and place a Cucumber hook in Cypress/support/index.js such as
Before(() => {
cy.log('Anything?');
});
And you can see this hook is not run and nothing is logged. If you change it to the mocha hook
before(() => {
cy.log('Anything?');
});
You will see this run and log Anything?.
Versions
- Cypress version: 4.4.1
- Preprocessor version: 2.3.1
- Node version: 12.2.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
What are Cypress Hooks and How to use Hooks in Cypress?
It runs once after completion of all the tests specified using “it” or “specify” in the “describe” or “context” block.
Read more >Execution order of after hooks when globally defined is not ...
js do not execute last - the after hooks defined in the spec file run last. I verified this is not a UI...
Read more >Writing and Organizing Tests - Cypress Documentation
Cypress also provides hooks (borrowed from Mocha). These are helpful to set conditions that you want to run before a set of tests...
Read more >Cypress E2E: Before hook not working on retries
let isError = false; beforeEach(() => { cy.once('fail', (err) => { isError = true; throw err; }); if (isError) { cy.resetAll(); // or ......
Read more >cypress-cucumber-with-tags - NPM Package Overview - Socket
cypress /support/step_definitions when nonGlobalStepDefinitions is false ... Cucumber Before hooks run after all Mocha before and beforeEach ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Here is a repo you can use for reproduction. In
support/index.jsthere is a Cucumber Before hook and a Mocha before hook. When you run the feature you can see that only the Mocha hook is being executed. I also tried removing the Mocha hook completely so only the Cucumber hook existed, but then no hooks were run.https://github.com/AlexK777/cypress-example-kitchensink
nvm usethenyarn.yarn cy:open.Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I’m very excited about. Furthermore, I’d like to thank @lgandecki ++ for all the work that they’ve done so far.
Read more about the transfer of ownership here.
The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.