Set environmental variables via npm script and command line #14292
|
Hello everyone, I'm trying to follow through this guide: https://glebbahmutov.com/blog/cypress-tips-and-tricks/#pass-the-environment-variables-correctly So I want to open cypress and also pass env variables for my tests, this should be done by using a script in my package.json. Here ist my current approach: my script lines (package.json) my powershell file (start.ps1): this my output in cypress browser (configuration tab) Do you have any suggestions what I am currently doing wrong here? I kinda ran out of ideas :) |
Replies: 8 comments 7 replies
|
Hi, can someone help, please? :) |
|
@TossExecutor, try next construction: |
|
Setting --env seems not to be possible for nested keys in cypress in accordance to documentation. You can try to use next construction. It's single line, but I think you would be able to handle how it works. export DB_CONFIG='{"database":"database_name"}' && cypress open --env db=${DB_CONFIG}
|
|
Unfortunately, those things won't work on a windows pc and Powershell. Could it be that Powershell is not supported in a way for cypress? |
|
It seems to me the problem is in setting the environment variables before running Cypress. Cypress just reads the variables, it has no control over setting them.
…Sent from my iPhone
On Jan 20, 2021, at 11:24, TossExecutor ***@***.***> wrote:
Unfortunately, those things won't work on a windows pc and Powershell. Could it be that Powershell is not supported in a way for cypress?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
|
Seems your shell does not interpolate variables inside |
|
Hi @bahmutov I have watched your video and it was very informative however I am still having issues. This is my |
|
I have opened an issue #15323 about parsing JSON objects in |



Seems your shell does not interpolate variables inside
npm runscripts. I have no idea what it does or why it does not work as other shells. I have recorded a video showing my experience with passing the environment variables: https://youtu.be/jAiYePsxPl4 At the end I suggest using the plugin file to grab the environment variables and avoid relying on the shell.