GetUserMedia – The Pain of Testing?

Don’t get us wrong. Testing is a crucial part in the software development process. That doesn’t mean to hire 100 students to do some monkey testing, but to have a good suite of automated tests. Nevertheless it still can be hard sometimes to wrap your mind around complex test setups.

We came across a special issue regarding getUserMedia and want to share our solution to ease the process for others a little. HTML5 allows us to access the camera and microphone of our devices and to protect the user’s privacy, of course not before his agreement. Since we use the awesome Selenium to test our UIs, we don’t have access to the browser’s chrome. We use a local chrome web driver for now, to do our ui-testing and struggled to get it working, because there are only some rough explanations on how to simulate the users agreement. Here are our findings:

  1. DriverOptions and Capabilities are not the same. A little bit confusing at the beginning.
  2. You will need a custom user profile. The easiest way is to load chrome portable and use theirs. It is an .exe file, which will download chrome for you and will store it in the folder GoogleChromePortable. Afterwards you have to start it once, so chrome will create the default profile in Data/profile. There is no need to modify anthing, just keep track of the path to the Data/profile folder and use it as shown in the code snippet below.
  3. Then configure your testdriver to look something like this:
var chrome = require('selenium-webdriver/chrome');  
var chromeOpts = new chrome.Options();  
chromeOpts.addArguments([  
    '--user-data-dir=<absolute path to the data/profile folder here>', *1
    '--disable-user-media-security',
    '--use-fake-ui-for-media-stream', 
    '--use-fake-device-for-media-stream', 
    '--disable-web-security', 
    '--reduce-security-for-testing']
);

var driver = new webdriver.Builder().setChromeOptions(chromeOpts)  
// and so on …

*If you are using Windows, keep in mind, that you need to transform all backslashes in the path to the profile directory to slashes, otherwise you will get an error.

The options are mostly self-explaining, but if you are interested, here is a list of all possible options with an explanation. Hope that saves you some time and as you can see, there might be some pitfalls, but once you have everything set up, you will feel much more confident about your solutions. Testing is awesome!

Veröffentlicht in Allgemein