cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.84k stars 3.17k forks source link

baseUrl in cypress.config.ts won't get overwritten by setting CYPRESS_baseUrl or CYPRESS_BASE_URL #29556

Open Baluditor opened 4 months ago

Baluditor commented 4 months ago

Current behavior

I have the following cypress.config.ts:

import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    experimentalModifyObstructiveThirdPartyCode: true,
    baseUrl: 'http://localhost:3000',
  },

  component: {
    devServer: {
      framework: 'react',
      bundler: 'vite',
    },
  },

  env: {
    baseUrl: 'http://localhost:3000',
    authUrl: 'https://localhost:4013',
    ... 
  },
});

and my test.yml file:

name: Run tests
on: [pull_request]

jobs:
  cypress-e2e-run:
    name: Cypress E2E tests
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: add deployment configuration for main branch
        run: |
          cat testing.env.conf >> $GITHUB_ENV

      - name: Cypress E2E tests
        uses: cypress-io/github-action@v6
        with:
          browser: chrome
        env:
          CYPRESS_userName: ${{ secrets.CYPRESS_USER_NAME_TESTING }}
          CYPRESS_password: ${{ secrets.CYPRESS_PASSWORD_TESTING }}
          # I tried with CYPRESS_AUTH_URL and CYPRESS_BASE_URL, same result
          CYPRESS_authUrl: ${{ env.VITE_APP_AZURE_B2C_AUTHORITY }}
          CYPRESS_baseUrl: ${{ env.swa_preview_hostname_first_part }}-${{ github.event.pull_request.number }}.${{ env.swa_preview_hostname_second_part }}

My issue is that the baseUrl will be http://localhost:3000 no matter what I do. I see that the env vars are set in Github Workflow: image

According to the docs this should work.

Desired behavior

My expectations is that baseUrl overwritten.

Test code to reproduce

N/A

Cypress Version

Cypress package version: 13.8.1

Node version

Node version: 18.17.1

Operating System

ubuntu-22.04

Debug Logs

No response

Other

No response

Baluditor commented 4 months ago

I've done some more testing and I found the following:

 # Base URL overwrite is somewhat working. Withouth it, the test would run agains the localhost. Setting it solves that issue, but accessing it with cypress.env('baseUrl') will still returns 'localhost'.
CYPRESS_baseUrl: ${{ env.swa_preview_hostname_first_part }}-${{ github.event.pull_request.number }}.${{ env.swa_preview_hostname_second_part }}
 # But baseUrl still can't be used in the tests, thus setting a hostUrl variable which will have the correct value.
CYPRESS_hostUrl: ${{ env.swa_preview_hostname_first_part }}-${{ github.event.pull_request.number }}.${{ env.swa_preview_hostname_second_part }}

So basically, I had the assumption that overwriting the baseUrl would affect the e2e baseUrl too, but this dosen't seem to work.