【问题标题】:Cypress failing test due to CORS?赛普拉斯因 CORS 未能通过测试?
【发布时间】:2022-01-18 18:39:11
【问题描述】:

我有一个由于CORS 而失败的简单测试,我不确定如何修复它:

    it("Visits home", () => {
        cy.visit("http://localhost:3000");
    });

这是错误:

  1) Test
       Visits the home page:
     SecurityError: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.

【问题讨论】:

    标签: reactjs unit-testing iframe cross-domain cypress


    【解决方案1】:

    转到cypress.json 并添加:

    chromeWebSecurity: false
    

    在基于 Chrome 的浏览器中将 chromeWebSecurity 设置为 false 允许您执行以下操作:

    • 显示不安全的内容
    • 导航到任何超级域,不会出现跨域错误
    • 访问嵌入在您的应用程序中的跨域 iframe

    【讨论】:

    • 谢谢,已解决
    猜你喜欢
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 2023-02-14
    • 2021-10-20
    • 2020-05-16
    • 1970-01-01
    相关资源
    最近更新 更多