This article explains how to test web application that use web cam. We use Python Splinter and fake a webcam device using Chrome web driver.
The challenge here is to fake the webcam with proper video format. In this post I am using Chrome browser along with Splinter. If you are new to Splinter, check out my article and I promise you love it. We use Splinter not only for testing but also for web scraping. Chrome need Y4M format to replace the camera feed. To generate that format you need ffmpeg tool. Using that tool you can convert any MP4 video into Y4M format.
Y4M is an un-compressed format. The converted Y4M file size will be almost three times the MP4 file. So, take a small MP4 file or repeat the image to create the video.
Chrome Settings to fake webcam
We will set
webdriver.ChromeOptions to enable media stream using a fake device.
You are all set to test the web applications using a fake video. The complete source code along with the sample web application (using Python Flask) is available as a gitlab project.