enhanced documentation
Showing
1 changed file
with
55 additions
and
4 deletions
... | @@ -2,8 +2,9 @@ | ... | @@ -2,8 +2,9 @@ |
2 | 2 | ||
3 | 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: | 3 | 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: |
4 | 4 | ||
5 | - chaining navigation steps | 5 | - defining & ordering navigation steps |
6 | - capturing screenshots of a page (or an area) | 6 | - capturing screenshots of a page (or an area) |
7 | - making assertions on remote DOM | ||
7 | - logging events | 8 | - logging events |
8 | - evaluating dynamic code within the remote page environment | 9 | - evaluating dynamic code within the remote page environment |
9 | - retrieve base64 encoded version of remote resources | 10 | - retrieve base64 encoded version of remote resources |
... | @@ -194,7 +195,43 @@ casper.run -> | ... | @@ -194,7 +195,43 @@ casper.run -> |
194 | 195 | ||
195 | ## Casper.js API Documentation | 196 | ## Casper.js API Documentation |
196 | 197 | ||
197 | Code is quite heavily documented using `jsdoc`, but here are the whole API documentation with sample examples supplied: | 198 | Code is quite heavily documented using `jsdoc`, but below you'll find the whole API documentation with added sample code added. |
199 | |||
200 | ### Casper([Object options]) | ||
201 | |||
202 | Casper constructor accepts a single `options` argument which is an object. Available options are: | ||
203 | |||
204 | ``` | ||
205 | Name | Type | Default | Description | ||
206 | ——————————————————+——————————+—————————+———————————————————————————————————————————————————————————————————— | ||
207 | clientScripts | Array | [] | A collection of script filepaths to include to every page loaded | ||
208 | logLevel | String | "error" | Logging level (see logLevels for available values) | ||
209 | onDie | function | null | A function to be called when Casper#die() is called | ||
210 | onPageInitialized | function | null | A function to be called after WebPage instance has been initialized | ||
211 | page | WebPage | null | An existing WebPage instance | ||
212 | pageSettings | Object | {} | PhantomJS's WebPage settings object | ||
213 | verbose | Boolean | false | Realtime output of log messages | ||
214 | ``` | ||
215 | |||
216 | Example: | ||
217 | |||
218 | ``` javascript | ||
219 | phantom.injectJs('path/to/casper.js'); | ||
220 | |||
221 | var casper = new phantom.Casper({ | ||
222 | clientScripts: [ | ||
223 | 'includes/jquery.js', | ||
224 | 'includes/underscore.js' | ||
225 | ], | ||
226 | logLevel: "info", | ||
227 | pageSettings: { | ||
228 | loadImages: false, | ||
229 | loadPlugins: false | ||
230 | } | ||
231 | }); | ||
232 | ``` | ||
233 | |||
234 | But no worry, usually you'll just need to instantiate Casper using `new phantom.Casper()`. | ||
198 | 235 | ||
199 | ### Casper#base64encode(String url) | 236 | ### Casper#base64encode(String url) |
200 | 237 | ||
... | @@ -292,8 +329,8 @@ casper.evaluate(function() { | ... | @@ -292,8 +329,8 @@ casper.evaluate(function() { |
292 | document.querySelector('#password').setAttribute('value', '%password%'); | 329 | document.querySelector('#password').setAttribute('value', '%password%'); |
293 | document.querySelector('#submit').click(); | 330 | document.querySelector('#submit').click(); |
294 | }, { | 331 | }, { |
295 | username: 'Bazoonga', | 332 | username: 'sheldon.cooper', |
296 | password: 'baz00nga' | 333 | password: 'b4z1ng4' |
297 | }); | 334 | }); |
298 | ``` | 335 | ``` |
299 | 336 | ||
... | @@ -444,6 +481,20 @@ casper.start('http://google.fr/').then(function(self) { | ... | @@ -444,6 +481,20 @@ casper.start('http://google.fr/').then(function(self) { |
444 | }).run(); | 481 | }).run(); |
445 | ``` | 482 | ``` |
446 | 483 | ||
484 | ### Casper#thenOpenAndEvaluate(String location[, function then, Object replacements]) | ||
485 | |||
486 | Basically a shortcut for opening an url and evaluate code against remote DOM environment. | ||
487 | |||
488 | Example: | ||
489 | |||
490 | ``` javascript | ||
491 | casper.start('http://google.fr/').then(function(self) { | ||
492 | self.echo("I'm in your google."); | ||
493 | }).thenOpenAndEvaluate('http://yahoo.fr/', function() { | ||
494 | document.querySelector['form'].submit(); | ||
495 | }).run(); | ||
496 | ``` | ||
497 | |||
447 | ## Licensing | 498 | ## Licensing |
448 | 499 | ||
449 | `Casper.js` is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License). | 500 | `Casper.js` is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License). | ... | ... |
-
Please register or sign in to post a comment