Reputation: 5834
After reading the Cypress documentation on web security and when to disable it, I've decided I indeed need to do it. Is there a way to disable this just for one particular test/test suite? I'm using version 3.4.1 and this config is being set in cypress.json
- therefore it's global for all tests.
Is there a way to disable web security just for one test? Thanks!
Upvotes: 16
Views: 21201
Reputation: 412
In my case it worked as follows.
the first thing was to set chromeWebSecurity
to false
//cypress.json
{
"chromeWebSecurity": false
}
Then what I do is with a before assign it to true
with Cypress.config
//cypress/integration/testing.spec.js
context('DEMO-01', () => {
beforeEach(function () {
Cypress.config('chromeWebSecurity', true);
});
describe('CP001 - start dasboard', () => {
it('P01: open dashboard', () => {
cy.visit(URL);
});
});
});
Upvotes: 0
Reputation: 500
Original answer:
Does this work for you?
describe("test the config json", function () {
it("use web security false here", function () {
Cypress.config('chromeWebSecurity',false);
cy.visit("https://www.google.com");
console.log(Cypress.config('chromeWebSecurity'));
});
it("use web security true here", function () {
Cypress.config('chromeWebSecurity',true);
cy.visit("https://www.google.com");
console.log(Cypress.config('chromeWebSecurity'));
});
});
The config is changed as you can see from the console log.
See document here https://docs.cypress.io/guides/references/configuration.html#Cypress-config
Updates:
After I saw DurkoMatKo's comment I managed to find an URL to test this 'chromeWebSecurity' option. It did not work as expected. I think changing this config might not work during running the same browser as this is more like a browser feature which will determine when start. In this case what I can think of is only to run Cypress with different configurations.
The cypress doc here shows clear steps to do this. hope this helps.
Upvotes: 1