Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically set baseUrl in cypress.json

I have a laravel app and have brought in Cypress testing. In my cypress.json file I have the baseUrl value set to a string of localhost:8000. The issue is the cypress test baseUrl will change based on which environment I am on (Local, Production etc...) so is there a way to set this baseUrl dynamically in the cypress.json file? I ask about the Laravel .env because the baseUrl or APP_URL is already set there.

Thanks.

Current cypress.json

  "baseUrl": "http://127.0.0.1:8000", //How to make this dynamic based on app environment?
  "chromeWebSecurity": false
like image 578
CodeConnoisseur Avatar asked Jul 17 '26 01:07

CodeConnoisseur


1 Answers

You can change the value of the baseURL from the cli something like this:

npx cypress run --config baseUrl=https://example.com/

Or, a better approach would be to create multiple commands under scripts tag in your package.json like this:

"scripts": {
  "test": "cypress run",
  "test:staging": "cypress run --config baseUrl=https://staging-example.com/",
  "test:prod": "cypress run --config baseUrl=https://prod-example.com/"
}

And then you can directly run:

npm run test:staging
npm run test:prod
like image 123
Alapan Das Avatar answered Jul 19 '26 15:07

Alapan Das