Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set baseUrl and other env via dotenv #30784

Open
MadnezGirl opened this issue Dec 18, 2024 · 1 comment
Open

Set baseUrl and other env via dotenv #30784

MadnezGirl opened this issue Dec 18, 2024 · 1 comment

Comments

@MadnezGirl
Copy link

MadnezGirl commented Dec 18, 2024

Current behavior

I want to set baseUrl with CYPRESS_BASE_URL via .env file in root folder that near cypress.config.ts.
It will be more comfortable instead setting it in cmd every time.
But it doesn't work. Why I cant do it?
I saw similar issue but it closed cypress-io/github-action#174
Also I want overwrite "visit" command and use CYPRESS_PROXY_TOKEN env from .env file. BUT it also doesn't work. All environment variables are only available within the tests themselves.

Desired behavior

No response

Test code to reproduce

My config:

 const envLocal = dotenv.config({ path: path.resolve(process.cwd(), '.env') });

 export default defineConfig({
 ......
        env: {
            ...envLocal.parsed,
          },
 .....
 });

My .env file:

CYPRESS_PR_AUTH_PROXY_TOKEN=1234556668897866
CYPRESS_BASE_URL=https://testsite.ru

My command "visit":

Cypress.Commands.overwrite('visit', (origFunc, url, options) => {
    const qs = { token: Cypress.env('PR_AUTH_PROXY_TOKEN') };

    document.cookie = `token=${Cypress.env('PR_AUTH_PROXY_API_TOKEN')};`;

    return origFunc(url, { ...options, qs });
 });

Cypress Version

12.17.3

Node version

18.12.0

Operating System

macOS

Debug Logs

No response

Other

No response

@MadnezGirl MadnezGirl changed the title Set baseUrl and another env via dotenv Set baseUrl and other env via dotenv Dec 18, 2024
@MadnezGirl
Copy link
Author

MadnezGirl commented Dec 18, 2024

It work in "visit" command via .env file if I set

Cypress.env('CYPRESS_PR_AUTH_PROXY_TOKEN')

BUT if I set it via cmd so I need to use in "visit" command

Cypress.env('PR_AUTH_PROXY_TOKEN')

WHY????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant