Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Cypress.config().baseUrl with environment variable (process.env)

Tags:

cypress

I was to set the baseURL of my cypress tests to be read from .env file.

I can't set it directly in the cypress.json file. And when I try to use cy.visit(process.env.MYAPPURL), I get an this error

cy.visit() must be called with a url or an options object containing a url as its 1st argument

enter image description here

like image 809
Mona101ma Avatar asked Sep 06 '25 03:09

Mona101ma


1 Answers

you can leave cy.visit() empty but you just need to set this env CYPRESS_BASE_URL with the base url instead like this for example:

CYPRESS_BASE_URL=$VUE_APP_BASE_URL

check this for explanation https://docs.cypress.io/guides/guides/environment-variables

like image 167
mosaad Avatar answered Sep 08 '25 01:09

mosaad