Set variables and run npm script

I’m working with Cypress and I want to use CLI tools to set environmental variables (no windows environmental variables) for the Cypress testing runner. Something is clearly not working and I kinda run out of ideas why that could be.

Here is the guide I was following through:
https://glebbahmutov.com/blog/cypress-tips-and-tricks/#pass-the-environment-variables-correctly

Here is my original post in the Cypress Github Discussions (no solution yet):

And here is a picture which explains quite well what I am trying to do:

For clarity, the first attempt should work.

Do you have an idea of what I am missing here?

 

Looks like actual PowerShell command work fine. After reviewing the Cypress tips (link you posted), I the variables need to be in single quotes. Have you tried that?

cypress open --env user='$DB_USERNAME',password='$DB_PASSWORD'

 

Thank you very much for the quick reply.

Yes, I have tried that.

PS C:\Users\...\Documents\cypressTesting> $credential = $host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.", "", "")
$DB_PASSWORD = $credential.GetNetworkCredential().password
$DB_USERNAME = $credential.GetNetworkCredential().username

PS C:\Users\...\Documents\cypressTesting> npm run cy:open

> cypresstesting@1.0.0 cy:open C:\Users\...\Documents\cypressTesting
> cypress open --env user='$DB_USERNAME',password='$DB_PASSWORD'

This is the result I’m getting:

Edit:
Could it be that Powershell does not interpolate variables inside npm run scripts? It seems that it works flawlessly in other shells.

 

You guys have any idea why Powershell seemingly does not interpolate the variable inside npm run?

Or do you have an idea of how I can work around that?

 

Cheers

I’m pretty sure this is NOT a PowerShell issue. Have you tried it from cmd.exe? Once you type “npm run cy:open” and press enter I believe you are interacting with that program not PowerShell.