Cypress Dynamic BaseURL

Profile picture for user arilio666

The cypress URL can be dynamically used and set as the base URL in the cypress config to load the URL from the config file.

URLs are set in this place and invoked to call the set URL dynamically. In the cypress.config.js, add the following line inside env.

 env: {
   baseUrl: '',
  • In the spec file, the baseURL is called like this,
  • For a more dynamic approach, we can follow this.
npx cypress run --config baseUrl=


  • In the package.json, we can set a script like the one below.
"scripts": {
 "test": "cypress run",
 "test:staging": "cypress run --config baseUrl=",
 "test:prod": "cypress run --config baseUrl="
  • Then can directly run.
npm run test:staging
npm run test:prod