仅在一次测试中禁用赛普拉斯中的网络安全 [英] Disable web security in Cypress just for one test

查看:22
本文介绍了仅在一次测试中禁用赛普拉斯中的网络安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读完赛普拉斯

在此处查看文档 https://docs.cypress.io/guides/references/configuration.html#Cypress-config

更新:

在我看到 DurkoMatKo 的评论后,我设法找到了一个 URL 来测试这个chromeWebSecurity"选项.它没有按预期工作.我认为在运行同一个浏览器期间更改此配置可能不起作用,因为这更像是决定何时启动的浏览器功能.在这种情况下,我能想到的只是以不同的配置运行赛普拉斯.

赛普拉斯文档这里显示了明确的步骤这.希望这可以帮助.

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!

解决方案

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.

这篇关于仅在一次测试中禁用赛普拉斯中的网络安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆