As a rule of thumb anything you call from Cypress
affects global state. Anything you call from cy
affects local state.
Since the environment variables added or changed by Cypress.env
are only in scope for the current spec file, you’d think that it should be cy.env
and not Cypress.env
… and you’d be right. The fact that Cypress.env
affects local state is an artifact of the API evolving over time: Cypress.env
used to affect global state—environment variables added in one test spec file were available in other specs—but the Cypress team wisely made each spec run in isolation in 3.0.0
and by that time Cypress.env
was public API.
Further reading: https://docs.cypress.io/api/cypress-api/env.html#Why-is-it-Cypress-env-and-not-cy-env
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.