0

In my case I need emulate camera to use it on chromium.

I already tried command like this:

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

and it works fine. But when I add it on my codecept.conf.js it doesn't. I still get error "can't get access to camera". What I did wrong in configuration file?

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 Answers1

1

Answer is https://nodejs.org/api/path.html

On Windows:

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

need edit start option like this:

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

Much better way is use path.join method. codecept.conf.js should look like this:

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

Using this way your script will always work on any platform. Note: video file in my example placed in root project directory.

  • Could you show how this relates to the question - where does this go in the config file? – jonrsharpe Mar 01 '19 at 17:28
  • You should look more attentively to my answer. As you can see, the path to file which needed to emulate cam must be with too (2) slashes. Because nodejs "eated" one slash. – Андрей Корниенко Mar 04 '19 at 14:13
  • Think about this from the perspective of somebody else with the same problem. How do they apply your answer to their configuration file to *actually solve it*? I've read your answer, it's not like it took very long, and I'm giving you feedback that would allow you to improve it. – jonrsharpe Mar 04 '19 at 14:14