Editor: Check out this guest blog post by Igor Ribeiro Lima on how use the commandline to perform cross browser testing.

We all know that testing your JavaScript code is a good thing, but one of the hurdles to overcome is how to test the code on different browsers. With this challenge in mind I developed a CLI tool named saucie. This CLI is a library hosted on NPM which allows you to integrate your frontend JavaScript tests with SauceLabs platform. SauceLabs already has awesome cross browser testing, and saucie makes it easier to do that cross browser testing via a CLI.

A great interactive JavaScript test runner, the testem library, uses saucie on its examples and has the following jasmine sample tests:

hello.js

```js function hello(name){ return “hello “ + (name || ‘world’); } ```js

hello_spec.js

```js describe(‘hello’, function(){ it(‘should say hello’, function(){ expect(hello()).toBe(‘hello world’); }); it(‘should say hello to person’, function(){ expect(hello(‘Bob’)).toBe(‘hello Bob’); }); }); ```js

To run these tests cross platform, you only need to execute a few commands, as described below:

1. First, create your SauceLabs account

2. Make sure Sauce credentials are set as environment variables:

`SAUCE_USERNAME` – your SauceLabs username

`SAUCE_ACCESS_KEY` – your SauceLabs API/Access key

3. Now, follow the script below:

npm install -g testem saucie
git clone git@github.com:airportyh/testem.git
cd testem/
git checkout tags/v0.7.1
cd examples/saucelabs/

Keep that first terminal open, then open a second terminal and use the script below:

cd testem/examples/saucelabs/
testem --port 8080

Go back to the first terminal and type:

saucie --browserNameSL="internet explorer" --versionSL="7.0" --platformSL="Windows XP"

saucie --browserNameSL="iphone" --versionSL="8.1" --platformSL="OS X 10.10" --deviceNameSL="iPad Simulator" --deviceOrientationSL="portrait"

saucie --browserNameSL="android" --versionSL="4.1" --platformSL="Linux" --deviceNameSL="Motorola Atrix HD Emulator" --deviceOrientationSL="portrait"

Some notes…

  • All platforms are listed here. Want to know what the values for the browserNameSL, versionSL and platformSL params are? Check them here.
  • If you’d like to use the default configuration, just type testem ci --port 8080
  • type saucie --help to get a help.
  • testem.yml is a configuration file where specifies which JavaScript framework to use. In this case, we are using JasmineJS.

Watch a demo

Click on the screenshot below to watch a command line demo of Saucie in action!

Screen Shot 2015-03-11 at 2.35.08 PM

As you can see, with just a few commands we were able to test across cross browsers. Now, let’s go to SauceLabs and check the results, including the mobile ones such as iOS and Android:

Saucie will soon integrate other platforms like BrowserStack. The project also recently got various improvements from johanneswuerbach. He made several changes to use Saucie in ember-cli-sauce, which is now used by htmlbars, the rendering engine used by emberjs.

Feel free to file issue and send pull requests and let’s become Saucie even better. Thanks!