【问题标题】:Disable Chrome Web Security for Cypress Testing为 Cypress 测试禁用 Chrome 网络安全
【发布时间】:2021-11-03 15:00:15
【问题描述】:

作为一名测试人员,我正在测试一个软件套件。 我有多个测试,其中一个测试需要 chromeWebSecurity 为真,另一个测试需要 chromeWebSecurity(iFrames CORS 错误) 为假。 所以我希望能够在测试开始之前而不是在 Cypress.json 中更改 chromeWebSecurity。

cy.log(Cypress.config("chromeWebSecurity"));
Cypress.config("chromeWebSecurity", false);
cy.log(Cypress.config("chromeWebSecurity"));

我已经尝试过上面的一点,它在记录时更改了 chromeWebSecurity,但没有成功运行测试。

【问题讨论】:

  • Cypress.config("chromeWebSecurity", false); 这个命令看起来是正确的。请添加您的完整测试。
  • Cypress.config("chromeWebSecurity", false) 在测试运行开始后无效。

标签: cypress websecurity


【解决方案1】:

虽然可以在测试期间使用

更改赛普拉斯配置对象
Cypress.config("chromeWebSecurity", false)

此更改不起作用,因为此配置项在浏览器启动期间使用。

尝试重构导致 CORS 错误的测试。

如果是登录场景,您可以使用cy.request() 而不是访问登录页面,或者在beforeEach() 中使用cy.session() 执行登录访问以保留登录令牌。

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 2019-06-21
    • 2016-01-11
    • 2016-12-11
    • 2016-06-21
    • 2020-01-22
    相关资源
    最近更新 更多