Cross-origin testing with Cypress

S Chathuranga Jayasinghe
2 min readOct 22, 2021

Cypress does not support cross-domain tests.. Yes & true, But.. there is a work-around! :)

You are reading this because, you have already heard that Cypress does not support cross-domain testing within a single test. Yes it is true and mentioned here in Cypress Docs too.

An image from Cypress Docs

Chill! There is a work-around for this head-burning LIMITATION. Let’s get on with it..

Step 1: Setting chromeWebSecurity to false

In your Cypress project, open the cypress.json file. If the files contains an attribute named as “chromeWebSecurity” set the value of it to false. If this attribute is not there add it as follows:

"chromeWebSecurity": false

Step 2: Write a Custom Command

Open the commands.js file in your Cypress project located under cypress/support folder. Add the following commands at the end of the file:

Cypress.Commands.add('forceVisit', url => {
cy.window().then(win => {
return win.open(url, '_self');
});
});

Step 3: Write a Test Case & Check!

--

--