Casper is a navigation utility for [PhantomJS](http://www.phantomjs.org/).
Casper.js is a navigation utility for [PhantomJS](http://www.phantomjs.org/). It eases the process of defining a full navigation scenario and provides useful high-level function, methods & syntaxic sugar for doing common tasks such as:
More documentation to come soon, I swear. If you just can't wait, here's a sample script:
- chaining navigation steps
- capturing screenshots of a page (or an area)
- logging events
- evaluating dynamic code within the remote page environment
- retrieve base64 encoded version of remote resources
In the following example, we'll query google for two terms consecutively, `capser` and `homer`, and aggregate the result links in a standard Array. Running the script will output a standard JSON string containing both the logs and the results:
Proxy method for PhantomJS' `WebPage#render`. Adds a clipRect parameter for automatically setting page clipRect setting values and sets it back once done.
Evaluates an expression in the page context, a bit like what PhantomJS' `WebPage#evaluate` does, but can also replace values by their placeholer names.
Logs a message with an optional level in an optional space. Available levels are `debug`, `info`, `warning` and `error`. A space is a kind of namespace you can set for filtering your logs. By default, Casper logs messages in two distinct spaces: `phantom` and `remote`, to distinguish what happens in the PhantomJS environment from the remote one.
Runs the whole suite of steps and optionally executes a callback when they've all been done. Obviously, **calling this method is mandatory** in order to run the Casper navigation suite.
Configures and starts Casper, then open the provided `url` and optionnaly adds the step provided by the `then` argument.
Example:
``` javascript
casper.start('http://google.fr/',function(self){
self.echo("I'm loaded.");
}).run();
```
Alternatively:
``` javascript
casper.start('http://google.fr/');
casper.then(function(self){
self.echo("I'm loaded.");
});
casper.run();
```
Please note that **you must call the `start()` method in order to be able to add navigation steps** and run the suite. If you don't you'll get an error message inviting you to do so anyway.
### Casper#then(function fn)
The standard way to add a new navigation step to the Casper suite by provide a callback function which will be executed when the requested page is loaded.
`Casper.js` is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
## Now what
Feel free to play with the code and report an issue on github. I'm also reachable [on twitter](https://twitter.com/n1k0).
Feel free to play with the code and [report an issue on github](https://github.com/n1k0/casperjs/issues). I'm also reachable [on twitter](https://twitter.com/n1k0).