This article will quickly see how we can make cypress run on different environments using baseUrl method.
1.) Config File Setup.
- Go to cypress.config.js.

- Inside the e2e body, add the baseUrl and the URL to navigate.
2.) Spec File
- Create a spec file with Cypress.config().baseUrl.
describe('Conf Env Test',()=>{
it('Test',()=>{
let url = Cypress.config().baseUrl;
cy.visit(url);
})
})
- Now when we try to run the spec with cypress run, it will navigate to the site we provided as baseUrl in config.
3.) Override baseUrl
- Now we might think that the baseUrl is static and not dynamic, and how is this of any help?
- To achieve a dynamic pass, we can override baseUrl using cypress cli.
npx cypress run --spec cypress\e2e\Tests\confart.cy.js --config baseUrl="https://www.ivagus.com"