Is there any way to execute code once before all tests in Cypress? I need it to run only once before all specs. The problem I want to solve is to create some file needed for tests, prepare user permissions and so on.
I have tried 'before' hook in the support index.js file but it runs every test spec.
I have also tried to run conditional 'before' hook in index.js based on env variable which I set in the cypress.json file like so:
"env": {
"cypress_setup": false
},
I am changing the variable in the hook:
before(function () {
// Set user permissions
if (Cypress.env('cypress_admin') === false) {
// do some stuff
cy.log('o some stuff')
// Change the variable to mark the hook as executed
cy.exec('export cypress_admin="true"')
}
})
but seems Cypress sets original env variable value before each test.
I expect Cypress to support this type of action is some way.