We automate web application testing using Python Selenium or Splinter. How will you automate testing applications with webcam? You can fake a webcam device with Chrome Web driver. In this article we will see how to do that.
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 uing a fake video. The complete source code along with the sample web application (using Python Flask) is available as a gitlab project.