Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable web security in Cypress just for one test

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!

like image 671
DurkoMatko Avatar asked Sep 22 '19 10:09

DurkoMatko


1 Answers

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. enter image description here

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.

like image 101
Pigbrainflower Avatar answered Oct 26 '22 04:10

Pigbrainflower