cypress-io / cypress

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

Please add support for www.domain.com.localhost #25512

Open uflidd opened 1 year ago

uflidd commented 1 year ago

What would you like?

All browsers now support that you can open a domain locally by adding .localhost at end of the domain name,. Cypress however doesn't support this yet.

More specically: www.yourdomain.com goes to production www.yourdomain.com.localhost goes to your local (without you having to specify this in the host file)

Why is this needed?

We have a saas application that can be open in multiple domains. Manually having to update host file to add/remove hosts constantly is a painfully repeating operation.

Cypress testing would get an great enhancement for us that are working typically with apps that can be open by multiple domains.

Other

No response

Erenndriel commented 1 year ago

Hey @uflidd ! I wanted to know that when first visiting www.yourdomain.com.localhost and then e.g. visiting www.yourdomain2.com.localhost, does Cypress' outer URL get stuck in www.yourdomain.com.localhost ?

I'm having a similar issue (rather not a missing enhancement) where Cypress' doesn't trigger a full page load after visiting another subdomain if it first did visit one.

E.g.

I want to know if you have same exp as I do 'so that we may update the content of your issue to include this, or I then have to create a separate one.

Thanks for consideration!

olemarius commented 1 year ago

I found that this works (thanks to https://github.com/cypress-io/cypress/issues/1488#issuecomment-396435553)

export default defineConfig({
   ...
    hosts: {
        '*.localhost': '127.0.0.1'
    },
});

While this does NOT work for some reason:

export default defineConfig({
   ...
    hosts: {
        'www.adamogeva.no': '127.0.0.1'
    },
});

throwing the following error image

My test looks like this:

describe('hosts option in cypress config', () => {
    var baseUrl = 'https://www.adamogeva.no.localhost';
    it('Visit domain that is not added to localhost', () => {

        cy.visit(baseUrl);
        // I've added <div id="local">Local</div> on the website
        cy.get('#local')
            .should('exist')
            .and('have.text', 'Local'); 
    });
});

So the question is why domains doesn't work. The workaround would be to use .localhost baseUrls when running tests locally and just www.domain.com when running tests in production.