We’ve been working on developing tests for checking WebRTC connections in Licode and Google Chrome (stable and unstable versions). We started using Travis for the server tests some weeks ago, but at this time, we wanted to go beyond simple tests of Nuve and basic room’s functionality.
Our idea is to test publishng, subscribing and further features of our client library in Chrome and in future versions of Firefox. During these tests we need to automatically start Chrome, accept the browser’s GetUserMedia request, and to send a fake video stream to check whether streams are sent or not.
For this puporse we used three different and compatible frameworks:
Testacular also allows you to use several testing frameworks, but it comes with built-in Jasmine and Mocha integration.
We’ve also tested it against Mocha in our experiments, so you can choose your own framework.
We first need to install Chrome in the Travis machine for every test. Travis
helps us to do it by the before_install
command:
language: node_js
node_js:
- 0.8
before_install:
- ./.travis/scripts/install_chrome.sh
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
In this case you have to create the install_chrome.sh
script to
start chrome before the tests. You can access this script [here]
(https://github.com/ging/licode/blob/master/.travis/scripts/install_chrome.sh).
Since Travis runs npm test
for running tests we also need to
create a package.json
with info about the tests. Here we should
add the next lines to our code:
"scripts": {
"test": "./node_modules/coffee-script/bin/cake test"
}
And we’ll also add the corresponding Cakefile:
exec = require('child_process').exec
task 'test', 'run all tests suites', ->
console.log 'Running front-end tests'
chrome_bin = "DISPLAY=:99"
testacular = "#{__dirname}/node_modules/testacular/bin/testacular"
browsers = '.travis/chrome-start.sh'
options = "--single-run --browsers=#{browsers}"
exec "#{chrome_bin} #{testacular} start #{__dirname}/.travis/testacular.conf.js", (err, stdout, stderr) ->
console.error err if err
console.log stdout
In the chrome-start.sh file we have the corresponding starting scripts. With this script we setup Chrome with some default Chrome Preferences:
It allows the user to start Chrome and use Webrtc from a local URL (http://localhost:9876/) without asking permissions. This is configured in the Preferences file.
It also starts Chrome by using a fake video device, that is used to send
synthetic video packets between clients. This is achieved in the starting script,
with the option: --use-fake-device-for-media-stream
. Below you can see the resulting video.
For testing we used Jasmine and its asynchronous functionalities. We use it to test Licode but it can also be used to test WebRTC applications. Below we show one of our examples in the test cases:
it('should get access to user media', function () {
var callback = jasmine.createSpy("getusermedia");
localStream = Erizo.Stream({audio: true, video: true, data: true});
localStream.addEventListener("access-accepted", callback);
localStream.init();
waitsFor(function () {
return callback.callCount > 0;
});
runs(function () {
expect(callback).toHaveBeenCalled();
});
});
In this example we call the GetUserMedia command, and it automatically accepts on behalf of the user given the previous configuration. Once it is accept we check whether the Jasmine’s Spy has been called.