Starting from Cypress version 9.6, it is possible to handle multiple domains within a single test. Prior to version 9.6, Cypress only supported testing within a single domain.
You can set the initial domain in the Cypress configuration (for example, using the baseUrl setting) and then use the cy.visit() command in your test script to navigate to the website.
To handle multiple domains during test execution, you can use the cy.origin() command to switch between different domains as part of your test flow.
Make sure to enable the experimentalSessionAndOrigin flag in your Cypress configuration file (e.g., cypress.config.js or cypress.config.ts) to allow multi-domain testing.
Example Configuration:
// cypress.config.js
module.exports = {
experimentalSessionAndOrigin: true,
e2e: {
baseUrl: ‘https://example.com’,
},
};
Example usage in Script:
// Visit the main website (base URL defined in Cypress configuration)
cy.visit('/');
// Switch to a different domain using cy.origin()
cy.origin('https://another-domain.com', () => {
cy.visit('/');
cy.get('h1').should('contain', 'Welcome');
});