cy.log( "Environment: " + JSON.stringify(process.env,null,4) );
output in browser console
Environment: {}
It should not mutate/empty the process.env.
OS: Ubuntu 18
Cypress: 3.4.1
Could you please provide what the process.env value is here normally?
console.log(process.env) // <-- what does this print to console?
cy.log( "Environment: " + JSON.stringify(process.env,null,4) );
Not sure why but console.log doesn't work in case of cypress. I thought Cypress is overriding it.
@amitguptagwl it should be logging to the browser console when you run the tests.
use cypress open to open cypress in interactive mode, run the test and open browser console to see the log you added above.
Thanks @mpahuja .
@jennifer-shehane
It is {} in both case.
i am assuming you have read this? https://docs.cypress.io/guides/guides/environment-variables.html#Setting
@mpahuja Yes, I did. My question is about why process.env is empty? Because currently, I need to make multiple tasks to pass the correct environment variables to run my tests in a different environment. On top of that, I have the tasks to run the tests for the different user journey. They again need to be duplicated per environment.
Cypress is run in the browser environment, so there will is no access to Node in the browser nor Node's process.env within the spec files.
You can access Node, such as process.env within the support/index.js or plugins/index.js files however for use of any setup you require.
Impressive that Cypress supports 5 or 6 ways of setting environment variables, but surprising that the uber-popular dotenv is not one of them.
There's a plugin for dotenv, but I've wasted the last hour trying to get it to work, to no avail.
@dandv are you still having issues getting the plugin to work?
I've tested it using Cypress 4.9 and didn't see any issues.
Most helpful comment
Cypress is run in the browser environment, so there will is no access to Node in the browser nor Node's
process.envwithin the spec files.You can access Node, such as
process.envwithin thesupport/index.jsorplugins/index.jsfiles however for use of any setup you require.