Browser testing

Buster.JS offers multiple ways of running your tests in browsers. This document describes three ways, ranging from simple setup to most useful (if that’s a scale).

Running with buster server

Inspired by JsTestDriver, Buster.JS can automate browsers seamlessly and provide feedback anywhere you want, making running your tests in actual browsers easy and painless. Hell, it even makes it fun.

First, start a server:

../_images/buster-server-start.png

Then, capture how many browsers you want:

../_images/buster-server-capture-firefox.png

And simultaneously run tests on all the captured browsers:

../_images/buster-test-run-browsers.png

Running with buster static

Warning

This is still an experimental feature, but should work fine.

In the cases where you need a simpler method for running tests, but don’t care for the manual HTML scaffold (see next section), Buster.JS can serve the scaffold for you based on your configuration.

Start the server:

../_images/buster-static-start.png

Open the page in the browser and watch the tests run immediately:

../_images/buster-static-success.png

Using an HTML scaffold

Warning

This is still an experimental feature, but should work fine.

The simplest way to try Buster.JS is to copy the following code, save it to a file and run it in a browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
           "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>strftime</title>
  </head>
  <body>
    <script type="text/javascript" src="http://cdn.busterjs.org/releases/latest/buster-test.js"></script>
    <script type="text/javascript" src="http://cdn.busterjs.org/examples/strftime/strftime.js"></script>
    <script type="text/javascript" src="http://cdn.busterjs.org/examples/strftime/strftime-test.js"></script>
  </body>
</html>

Go ahead, try it.

If you use Git, you can clone this example to your machine:

git clone git://gist.github.com/1904218.git gist-1904218

Note

If you opt for downloading the script locally, remember to get the CSS file too. When using the pre-built library, there’s no installation, but you also miss out on much of the automation sweetness.

Running headless with PhantomJS

Warning

This feature has not yet landed in the beta.

The easiest way to run your tests with PhantomJS at the moment is by using the buster server method and the script provided to capture the browser.

Assuming you have installed PhantomJS separately and buster locally in your project:

buster-server
# on a separate terminal
phantomjs ./node_modules/buster/script/phantom.js &
buster-test

The phantom.js script will try to capture your browser on http://localhost:1111 If you’d like to confirm that it’s been captured, open that url in your browser and you’ll see the list of captured browsers.

In the future there will probably be an easier and more integrated way to run tests with PhantomJS.

Examples

Check the demos repository for example projects.