
How I stopped declaring login in each of my 5k tests
Have you ever encountered a testing codebase that many portions are repeated over and over? We all have! Of course, I could be talking about DRY princples (Don't Repeat Yourself), but lets keep that aside for now and focus on a Cypress trick up it's sleeve that can go unnoticed for many senior devs: the global hooks. And what do I mean by "global" hooks? They're called like that because you only declare them once and they're applied to all your tests instantly. So let's get to the grain here: when installing Cypress it already comes with a file at created at cypress/support/e2e.<ts|js> level. This is usually where you declare some important commands imports that your E2E testing will need to access and run properly. But it's also responsible for adding let's say before , beforeEach , or after , afterEach hooks that will be applied by all your tests. This can be responsible for login hooks, clean-ups to the database after the tests run, screenshots resolutions configuration -- a million
Continue reading on Dev.to
Opens in a new tab



