README.md

Ghostbuster

Automated browser testing via phantom.js, with all of the pain taken out! That means you get a real browser, with a real DOM, and can do real testing!

Installation

To install first gem install ghostbuster. Once you've done that, you can run setup-ghostbuster. Right now this only works on Mac, so, otherwise, ghostbuster will look for a copy of the phantomjs binary in ~/.ghostbuster.

Usage

Standalone

Once installed, you can simply use ghostbuster [path/to/Ghostfile] to run your tests.

Rake

As well, you can install Ghostbuster to run as a rake task. To do this, add this to your Rakefile:

Page Controls

get

This location will be relative to your root if it doesn't start with "http". Your callback will be called when the document is ready.

click

Arguments: selector, [index]

This will click the nth element matching the selector. If no index is specified it uses the first one found.

clickFollow

Arguments: selector, [index or options]

This will click the nth element matching the selector and assert the location changed. If no index is specified it uses the first one found.
If no path option is given, it will merely assert that the location changed.

input

Arguments: selector, text

This will fill in the matching form elements with the text given.

select

Arguments: selector, newValue

This will set a select box to a given value

wait

Arguments: seconds, callback

This will wait seconds secs and then call your callback.

Assertions

Assertions are run in order, and only one assertion at a time can run. An assertion will have at most one second to complete. If you want to change the total amount of time an assertion will take, you can supply that time.

The options for all assertions currently accepts total, which is the total amount of time this assertion will run for in seconds.

The available assertion function are available on body:

assertFirst

Arguments: selector, [options], callback

The callback will be called with the first matching DOM element for the selector. The callback must return true if this assertion is met.

assertAll

Arguments: selector, [options], callback

The callback will be called for each matching DOM element for the selector. The arguments supplied to the callback is the DOM element and the index (starting at 0). The callback must return true if this assertion is met.

assertLocation

Arguments: location, [options]

This assertion will attempt to match the current browser location. If your location does not start with http, it will be considered relative to the root of your test.

refuteLocation

Arguments: location, [options]

This assertion will attempt to refute the current browser location. If your location does not start with http, it will be considered relative to the root of your test.

assertCount

Arguments: selector, [options], callback

This callback will be called with the number of matching DOM elements for this selector. The callback must return true if this assertion is met.

assertCountAndAll

Arguments: selector, count, [options], callback

The callback will be called for each matching DOM element for the selector. It will only be called if the number of matching elements is equal to count. The arguments supplied to the callback is the DOM element and the index (starting at 0). The callback must return true if this assertion is met.

Before and After

You can add an arbitrary number of before and after blocks to be run within the context of your test. Simply call before and after on your test to add them. You have to call @succeed in the before block to continue processing your test.

phantom.test.before ->
# do some setup
@succeed()
phantom.test.after ->
# do some teardown