Monday, November 12, 2012

Introducing - Qunit tests on Grunt using Saucelabs services

The Grunt plugin for QUnit tests on Saucelabs services 
https://npmjs.org/package/grunt-saucelabs

For using it in your project, see the README

Most open source projects use Grunt + Qunit task to run test suites on the headless PhantomJS browser. This plugin extends the test matrix by running test suites on other 'cloudified browsers' using SauceLabs services.

Grunt is a task-based command line build tool for JavaScript projects. One of the things that Grunt enables is the ability to run Qunit Tests using PhantomJS. However, there could be cases when the QUnit tests need to run on other, non-webkit browsers too. Sauce Labs provides a cloud based browser environment with over 96 browser and OS combinations.
The interface to Sauce Labs browsers is based on a Selenium like WebDriver client that works over the wire using a JSON protocol. A node library also exists that can control the browsers remotely. Sauce Labs also provides the SauceConnect tool to tunnel into a system for testing localhost and other internal sites.
I came across using Saucelabs for testing in the pouchdb project. The pouch file establishes the tunnel, starts a server and runs the tests on Sauce Browsers. The file runs using node, but running it with grunt would make the code simpler. Many parts of this plugin are borrowed from the pouch file.
The syntax for using the plugin is very similar to Qunit, a few more parameters are specified in addition to the URLs to be tested. The plugin uses WebDriver to communicate with the browsers, load the page and wait for the Qunit tests to complete, very much like the Grunt Qunit plugin. Additionally, it also starts up the SauceConnect tunnel so that local pages can be loaded for testing. It also takes care of additional housekeeping things, like waiting for existing tunnels to close, killing orphan tunnels, etc.
This system can also be integrated with continuous integration systems like Travis. The IndexedDBShim project uses Travis and this plugin to test all commits against multiple browsers. Since environments like travis also allow secure environment variables, the sauce keys can be private, even in open source projects.

No comments:

Post a Comment