【问题标题】:Cypress throwing SecurityError赛普拉斯抛出 SecurityError
【发布时间】:2019-09-26 12:50:31
【问题描述】:

我目前正在运行 Chrome 74 并尝试使用 Cypress 在我的应用程序中测试样式指南。当我加载赛普拉斯时,它会抛出这个错误:

SecurityError: Blocked a frame with origin "http://localhost:3000" 从访问跨域框架。

如果有解决办法,请告诉我!

我曾试图遵循这一点: https://github.com/cypress-io/cypress/issues/1951

但没有任何改变/对我有用。 :(

我的代码如下图:cypress/plugins/index.js

module.exports = (on, config) => {
    on('before:browser:launch', (browser = {}, args) => {
        // browser will look something like this
        // {
        //   name: 'chrome',
        //   displayName: 'Chrome',
        //   version: '63.0.3239.108',
        //   path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
        //   majorVersion: '63'
        // }

        if (browser.name === 'chrome') {
            args.push('--disable-site-isolation-trials');

            return args
        }

        if (browser.name === 'electron') {
            args['fullscreen'] = true

            // whatever you return here becomes the new args
            return args
        }
    })
}

在我的cypress/support/index.js

这将在我运行的每个测试之前加载站点,以使自己不必在每个测试中编写 cy.visit。

beforeEach(() =>{
    cy.visit('http://localhost:3000/style-guide')
})

【问题讨论】:

    标签: google-chrome cypress


    【解决方案1】:

    所以,至少对我来说,我的进一步问题是一个带有令牌、登录等的内部问题。但是!

    我发布的关于插件文件夹中的索引如何正确绕过 chrome 问题的代码。这就是你想要修复它的方式!

    【讨论】:

      【解决方案2】:

      我昨天遇到了同样的问题,您在问题中提到的柏树 issue #1951@jsjoeio 的回答实际上对我有所帮助。

      所以基本上我所做的只是修改我的cypress.json 并添加以下值:

      {
        "chromeWebSecurity": false
      }
      

      【讨论】:

        【解决方案3】:

        我遇到了完全相同的问题,我建议您按照 DurkoMatko 的建议进行操作。 Documentation chromeWebSecurity

        但是我遇到了另一个问题,即 iframe 中指向 localhost 的链接。 如果您想在 iframe 中使用链接,我建议您这样做:

        cy.get('iframe').then((iframe) => {
          const body = iframe.contents().find('body');
          cy.wrap(body).find('a').click();
        });

        【讨论】:

          【解决方案4】:

          我也遇到过这个问题。我的应用程序正在使用服务人员。在访问页面时禁用服务人员解决了这个问题。

          cy.visit('index.html', {
            onBeforeLoad (win) {
              delete win.navigator.__proto__.serviceWorker
            }
          })
          

          参考:https://glebbahmutov.com/blog/cypress-tips-and-tricks/#disable-serviceworker

          【讨论】:

            【解决方案5】:

            您可以禁用安全性来解决此问题。

            1. 转到cypress.json 文件。
            2. { "chromeWebSecurity": false }并保存。
            3. 再次运行测试。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2020-12-23
              • 1970-01-01
              • 2018-04-28
              • 2023-01-12
              • 1970-01-01
              • 1970-01-01
              • 2019-11-07
              相关资源
              最近更新 更多