使用 chrome cypress 的标志运行测试

问题描述 投票:0回答:2

我有一些使用网络摄像头的测试用例,并且我们的测试环境需要使用网络摄像头在 chrome 中设置标志 --unsafely-treat-insecure-origin-as-secure

对于某些测试集,如何在 chrome 和 cypress 中使用此设置?

谢谢

testing cypress flags
2个回答
4
投票

您可以通过编写 Cypress 插件将标志传递到 Cypress 中的 chrome 浏览器,如官方文档所示:https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage

导航到您的

cypress/plugins
目录并添加以下代码

module.exports = (on, config) => {
  on('before:browser:launch', (browser = {}, launchOptions) => {
    // `args` is an array of all the arguments that will
    // be passed to browsers when it launches
  
    if (browser.name === 'chrome') {
      launchOptions.args.push('--unsafely-treat-insecure-origin-as-secure');
    }


    // whatever you return here becomes the launchOptions
    return launchOptions;
  });
};

0
投票

从 Cypress 13 (2024) 开始,您可以:

编辑

cypress.config.ts
添加:


export default defineConfig({
    ...
    
    e2e: {
        baseUrl: 'http://....',

        setupNodeEvents(on) {
            on('before:browser:launch', (browser, launchOptions) => {
                if (browser.family === 'chromium') {
                    launchOptions.args.push(
                        '--blink-settings=primaryPointerType=4'
                    )
                }

                return launchOptions
            })
        },
    },
})
© www.soinside.com 2019 - 2024. All rights reserved.