This recipe shows how to pass environment variables to your tests
- See package.json file which runs Cypress with environment variables set. The variables that start with
CYPRESS_are extracted automatically. Other variables are copied fromprocess.envin the setupNodeEvents function - Additional variables can be passed via
envobject in cypress.config.js - Extract any other variable from
process.envusing thesetupNodeEventsfunction. - Uses dotenv package to read the
.envfile in the Cypress configuraton - Keep secret or private variables server-side and read them in your spec with
cy.env():cy.env(['secret', 'password']). Values stay on the server; only the keys you request are returned to the spec. - Use
Cypress.expose()(and theexposeconfig /{ expose: {...} }test/suite override) only for values that are safe to expose everywhere — they are serialized into the config and readable in the browser and across every origin.