如何在codecept.conf.js中设置铬启动选项?

时间:2019-03-01 07:59:23

标签: chromium puppeteer codeceptjs

就我而言,我需要模拟相机才能在铬上使用它。

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

base64

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

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

1 个答案:

答案 0 :(得分: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'
}

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

相关问题