cypress-example-recipes
cypress-example-recipes copied to clipboard
.env and dotnev does not pass variables into Cypress.env
In the current version of the cypress-example-recipes/examples/server-communication__env-variables/.env , in the comment
# these variables will be read automatically
# CYPRESS_ part will be removed
# access them with Cypress.env("ping"), Cypress.env("HOST")
CYPRESS_ping=123
CYPRESS_HOST=laura.dev.local
cypress_api_server=http://localhost:8888/api/v1/
It suggests that variables will be read and they do appear as test asserts pass.
But it is passing due to the command-line argument, not the .env
file.
"cypress:open": "../../node_modules/.bin/cross-env FOO=42 BAR=baz CYPRESS_ping=123 CYPRESS_HOST=laura.dev.local cypress_api_server=http://localhost:8888/api/v1/ ../../node_modules/.bin/cypress open",
dotenv
correctly includes the content of the .env
into the process.env
object, however, while cypress does have CYPRESS_
variables submitted in the command line, it seems that the addition of the dotenv
comes too late and Cypress already passed over environment variables.
If that is the case then that comment and sample variables should be deleted as they are misleading.
Tested with: Cypress 11.1, macOS 11.13.6, node 16.15.1