Как настроить параметры запуска chromium в codecept.conf.js? - PullRequest
0 голосов
/ 01 марта 2019

В моем случае мне нужно эмулировать камеру, чтобы использовать ее на хроме.

Я уже пробовал команду, подобную этой:

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'
}

1 Ответ

0 голосов
/ 01 марта 2019

Ответ: 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'
}

Используя этот способ, ваш скрипт всегда будет работать на любой платформе.Примечание: видео файл в моем примере размещен в корневой директории проекта.

...