Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fake stream to Chrome instead of using WebCam

I am writing a test automation framework using Java and Selenium. I am running the tests both locally and also using Browserstack.

The website under tests includes features that use the PC's camera to scan documents and faces.

Instead of using the PC's webcam I want to fake a stream.

Has anybody managed to do this?

I am using the following Chrome options:

chromeOptions.addArguments("--use-fake-ui-for-media-stream");
chromeOptions.addArguments("--use-fake-device-for-media-stream");
chromeOptions.addArguments("--use-file-for-fake-video-capture=C:/deleteme/bus.y4m");

When I click on the button that would normally open the webcam, the webcam does NOT open, so it looks like it is doing something. However my video doesn't play.

Has anybody got these to work for a scenario similar to mine and could provide more info on how to do it?

Any help would be appreciated. Thanks.

like image 553
Matt Avatar asked Nov 04 '19 09:11

Matt


People also ask

What is use fake UI for media stream?

--use-fake-ui-for-media-stream avoids the need to grant camera/microphone permissions. --use-fake-device-for-media-stream feeds a test pattern to getUserMedia() instead of live camera input. --use-file-for-fake-video-capture=path/to/file. y4m feeds a Y4M test file to getUserMedia() instead of live camera input.

How do I change the video source in Chrome?

Option 1: Type about:preferences#privacy in the address bar then scroll down to the Permissions section, and click Settings. There you can choose which websites to Allow access to your microphone and camera. Scroll down till you see: Camera [Settings…] Select the webcam you want to use.


1 Answers

I solved that converting a mp4 file to mjpeg, which is a format that also can be used, and setting my chromedriver same as you did, but using a relative path to the file.

options.addArguments("--use-fake-ui-for-media-stream",
                     "--use-fake-device-for-media-stream",
                     "--use-file-for-fake-video-capture=src/test/resources/sample_640x360.mjpeg"); 

This thread helped me to get there: https://stackoverflow.com/a/52188760/1843429

like image 131
Lano Avatar answered Oct 09 '22 08:10

Lano