【问题标题】:How to set up chromium start options in codecept.conf.js?如何在 codecept.conf.js 中设置 chromium 启动选项?
【发布时间】:2019-07-23 05:30:56
【问题描述】:

在我的情况下,我需要模拟相机才能在 chromium 上使用它。

我已经尝试过这样的命令:

chrome.exe --use-fake-ui-for-media-stream --disable-web-security --use-fake-device-for-media-stream --use-file-for-fake-video-capture="C:\Users\user\Desktop\test\bridge_far_cif.y4m" --allow-file-access

而且效果很好。但是当我将它添加到我的 codecept.conf.js 时,它没有。我仍然收到错误“无法访问相机”。 我在配置文件中做错了什么?

exports.config = {
  tests: './*_test.js',
  output: './output',
  helpers: {
    Puppeteer: {
      url: 'https://url/',
      fullPageScreenshots: true,
         chrome: {
            args: ['--use-fake-ui-for-media-stream',
            '--disable-web-security',
            '--use-fake-device-for-media-stream',
            '--use-file-for-fake-video-capture="C:\Users\user\Desktop\test\bridge_far_cif.y4m"',
            '--allow-file-access',
            '--allow-running-insecure-content',
            ]
        }
    }
  },
  include: {
    I: './steps_file.js'
  },
  bootstrap: null,
  mocha: {},
  name: 'test',
  translation: 'ru-RU'
}

【问题讨论】:

    标签: chromium puppeteer codeceptjs


    【解决方案1】:

    答案是https://nodejs.org/api/path.html

    在 Windows 上:

    path.basename('C:\\temp\\myfile.html'); // 返回:'myfile.html'

    需要像这样的编辑开始选项:

    '--use-file-for-fake-video-capture="C:\\Users\\user\\Desktop\\test\\bridge_far_cif.y4m"'
    

    更好的方法是使用 path.join 方法。 codecept.conf.js 应该是这样的:

    const path = require('path');
    var fakeVideoFileName = 'fileName.y4m';
    var pathToFakeVideoFile =  path.join(__dirname, fakeVideoFileName);
    exports.config = {
      tests: './*_test.js',
      output: './output',
      helpers: {
        Puppeteer: {
          url: 'https://url/',
          fullPageScreenshots: true,
             chrome: {
                args: ['--use-fake-ui-for-media-stream',
                '--disable-web-security',
                '--use-fake-device-for-media-stream',
                '--use-file-for-fake-video-capture=' + pathToFakeVideoFile,
                '--allow-file-access-from-files',
                '--allow-running-insecure-content'
                ]
            }
        }
      },
      include: {
        I: './steps_file.js'
      },
    
      bootstrap: null,
      mocha: {},
      name: 'test',
      translation: 'ru-RU'
    }
    

    使用这种方式,您的脚本将始终在任何平台上运行。注意:我的示例中的视频文件放在项目根目录中。

    【讨论】:

    • 您能否说明这与问题的关系 - 它在配置文件中的什么位置?
    • 你应该更仔细地看我的回答。如您所见,需要模拟 cam 的文件路径也必须带有 (2) 个斜杠。因为 nodejs “吃掉”了一个斜线。
    • 从有同样问题的其他人的角度考虑这个问题。他们如何将您的答案应用于他们的配置文件以实际解决它?我已经阅读了您的回答,它不会花费很长时间,我正在给您反馈,以便您改进它。
    猜你喜欢
    • 2021-10-08
    • 2018-08-09
    • 2017-09-05
    • 2013-12-04
    • 2015-09-22
    • 1970-01-01
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多