Cypress throwing SecurityError

Hye*_*Eun 2 google-chrome cypress

我目前正在使用Chrome 74运行,并尝试使用赛普拉斯在我的应用中测试样式指南。当我加载赛普拉斯时,它将引发以下错误:

SecurityError: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.

如果有解决方案,请告诉我!

我试图跟着这样做: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
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

在我的 cypress/support/index.js

这将在每次运行测试之前加载该站点,以免于每次测试都必须编写cy.visit。

beforeEach(() =>{
    cy.visit('http://localhost:3000/style-guide')
})
Run Code Online (Sandbox Code Playgroud)

小智 11

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

  1. 转到cypress.config.js文件。
  2. 添加此行:chromeWebSecurity: false并保存。例如:
const { defineConfig } = require('cypress')

module.exports = defineConfig({
  ...,
  chromeWebSecurity: false // add this line
})
Run Code Online (Sandbox Code Playgroud)
  1. 再次运行测试。


Dur*_*tko 6

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

因此,基本上我唯一要做的就是修改我的代码cypress.json并添加以下值:

{
  "chromeWebSecurity": false
}
Run Code Online (Sandbox Code Playgroud)


Hye*_*Eun 3

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

我发布的代码说明了插件文件夹中的索引如何正确绕过 chrome 问题。这就是您想要解决的问题!