I want to be able to run my Cypress scripts on any URL by modifying the value of baseUrl but the command doesn't change it.
"cypress open --env version=development --config baseUrl=https://google.com"
I have tried env variable too but that also doesn't work:
"cypress:open:dev": "cypress open --env version=development,baseUrl=https://google.com"
Config file:
export default defineConfig({
  e2e: {
    async setupNodeEvents(on, config) {
      const version = config.env.version || 'development'
      const configFile = await import(path.join(
        config.projectRoot,
        'cypress/config',
        `${version}.json`
      ));
      const credentialsFile = await import(path.join(
        config.projectRoot,
        'cypress/config',
        'credentials.json'
      ));
      config = {
        ...config,                    // take config defined in this file
        ...configFile                 // merge/override from the external file
      }
      config.env = {
        ...config.env,                // 2nd level merge
        ...credentialsFile[version]   // from git-ignored file 
      }
      config.baseUrl = configFile.baseUrl
      return config
    },
    reporter: 'mochawesome'
  },
});
development.json:
{
    "env": {
        "baseUrl": "https://test.com",
    }
}
				
                        
Here is the solution that provides what I was looking for:
The command, URL is optional, if not provided it uses the hard-coded value in
development.json:The only line I needed to change in my config was the following:
All my tests were using the following:
So I needed to change to:
With this solution, I can run the script without any argument and it will use default
baseUrl, or I can runURL="https://google.com/ npm run cypress:open:devand thebaseUrlwill change