Commit 6165c26b 6165c26be03b58f0addf54429f9f5d96ff74172f by Nicolas Perriault

added events sample

1 parent 0d0e9621
......@@ -814,7 +814,7 @@ Casper.prototype.start = function(location, then) {
}
}, this.options.timeout, this);
}
casper.emit('casper.page.initialized');
this.emit('casper.page.initialized');
if (utils.isFunction(this.options.onPageInitialized)) {
this.log("Post-configuring WebPage instance", "debug");
this.options.onPageInitialized.call(this, this.page);
......
casper = require('casper').create()
casper.on "casper.http.status.200", (resource) ->
casper.echo "#{resource.url} is OK", "INFO"
casper.on "casper.http.status.301", (resource) ->
casper.echo "#{resource.url} is permanently redirected", "PARAMETER"
casper.on "casper.http.status.302", (resource) ->
casper.echo "#{resource.url} is temporarily redirected", "PARAMETER"
casper.on "casper.http.status.404", (resource) ->
casper.echo "#{resource.url} is not found", "COMMENT"
casper.on "casper.http.status.500", (resource) ->
casper.echo "#{resource.url} is in error", "ERROR"
links = [
'http://google.com/'
'http://www.google.com/'
'http://www.google.com/plop'
]
casper.start()
for link in links
casper.thenOpen link, -> @echo "#{link} loaded"
casper.run()
/**
* This script will add a custom HTTP status code handler, here for 404 pages.
*
*/
var casper = require('casper').create();
casper.on('casper.http.status.200', function(resource) {
casper.echo(resource.url + ' is OK', 'INFO');
});
casper.on('casper.http.status.301', function(resource) {
casper.echo(resource.url + ' is permanently redirected', 'PARAMETER');
});
casper.on('casper.http.status.302', function(resource) {
casper.echo(resource.url + ' is temporarily redirected', 'PARAMETER');
});
casper.on('casper.http.status.404', function(resource) {
casper.echo(resource.url + ' is not found', 'COMMENT');
});
casper.on('casper.http.status.500', function(resource) {
casper.echo(resource.url + ' is in error', 'ERROR');
});
var links = [
'http://google.com/',
'http://www.google.com/',
'http://www.google.com/plop'
];
casper.start().each(links, function(self, link) {
self.thenOpen(link, function() {
this.echo(link + ' loaded');
});
});
casper.run();