cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

`cy.visit()` should allow override of `baseUrl` #30000

Open mryellow opened 1 month ago

mryellow commented 1 month ago

What would you like?

cy.visit() should itself accept the option baseUrl: null.

Then it can be disabled on a case-by-case basis without impacting an entire test by specifying in options for it or by calling Cypress.config('baseUrl', null).

Why is this needed?

2918

4450

Other

https://github.com/cypress-io/cypress/blob/0fec07bf7184c9ce5cf0c9068cd5983d8002d93a/packages/driver/src/cy/commands/navigation.ts#L805-L813

neehhaa06 commented 1 month ago

Hello @mryellow :)

I think , The issue is that cy.visit() doesn’t support overriding baseUrl directly. Use Cypress.config('baseUrl', null) globally or manage URLs manually. Check Cypress docs and version for details.

cy.visit('https://another-url.com/path/to/page');
mryellow commented 1 month ago

file:// does not work in the same way.

It requires a relative path. Relative local paths are interpreted as URLs when baseUrl is set.

mryellow commented 1 month ago

You'll note the attached issues feature people needing to call Cypress.config('baseUrl', null') before their cy.visit().

Mutating the config for a single call seems a little harsh when what is really required is simply setting baseUrl for the single cy.visit() call. Which could be done by adding it to the options in the signature.