cypress: baseUrl not used in cypress.env.json

Current behavior

If you have a baseUrl in the cypress.env.json it’s not beeing used.

Desired behavior

just like the previous version I would like to have a local file cypress.env.json where the baseUrl is beeing read and used in my test.

Test code to reproduce

// Tried both ways and did not work

{
	"e2e": {
		"baseUrl": "https://google.com/"
	},
	"baseUrl": "https://google.com/"
}

Cypress Version

10.0.3

Other

It should work according the documentation: https://docs.cypress.io/guides/guides/environment-variables#Option-2-cypress-env-json

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (2 by maintainers)

Most upvoted comments

I believe I have a workaround for you guys @gagneet @bvanderneut , inside the setupNodeEvents I have this code

    const envKey = config.env.envKey || 'default';
    if (envKey !== 'default') {
      return getConfigByFile(envKey, config);
    } else {
      return config;
    }

and with this getConfigByFile function below I’m able to dynamically change the baseUrl or any config or env variable by choosing which config file to pass such as npx cypress open --env envKey=dev

  const fs = require('fs-extra');

  function getConfigByFile(envKey, config) {
  let fileName = `cypress_${envKey}.json`
  console.log("Config file: " + fileName);

  let rawData = fs.readFileSync(`cypress/config/${fileName}`);
  let newConfig = JSON.parse(rawData);

  config = {...config, ...newConfig}
  return config;
  };

I place this function anywhere outside of module.exports but still within the cypress.config.js

repo for reference:

@bvanderneut Thank you for the repro and apologies for my earlier response where I looked into cypress.config.js instead 😅 . I can confirm, you’ve found a buggo! 🐛 I’ll be passing this along to the team.

Repo with reproducible example Steps to test: yarn && npx cypress open -> e2e testing -> select baseUrl.cy.js

Hi

There is an issue with baseUrl.

The one that is taken into account by cypress is the one on the root of the configuration and not the one into the e2e object

What is written into the documentation is not correct

Capture d’écran 2022-06-10 à 13 46 11