question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

baseUrl not used in cypress.env.json

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
a8trejocommented, Aug 30, 2022

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:

1reaction
rachelrudermancommented, Jun 13, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment Variables | Cypress Documentation
However, you do not need to use environment variables to point to the origin and domain under test. Use baseUrl instead of environment...
Read more >
Switch between environments in Cypress - Filip Hric
The easiest way to switch environments is to simply rewrite your cypress.json file and set baseUrl to a different value each time you...
Read more >
Override Cypress.config().baseUrl with environment variable ...
env file. I can't set it directly in the cypress.json file. And when I try to use cy.visit(process.
Read more >
cypress-io/cypress - Gitter
baseUrl = config.env. ... I saw that fixtures don't have to be .json but I have not found an example of how ......
Read more >
Cypress v10 Environment Variables - Gleb Bahmutov
Cypress v10 has merged the plugins file with the cypress.json file into a single ... our project does not use fixture files
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found