Commit 157c1028 157c1028b906fdeab7f6bbd523b46a88538a574c by Nicolas Perriault

refactored some events; added customevents sample

1 parent 9c2102ca
......@@ -208,7 +208,7 @@ Casper.prototype.checkStep = function(self, onComplete) {
self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info");
self.page.content = ''; // avoid having previously loaded DOM contents being still active (refs #34)
clearInterval(self.checker);
self.emit('step.complete');
self.emit('run.complete');
if (utils.isFunction(onComplete)) {
try {
onComplete.call(self, self);
......@@ -653,7 +653,6 @@ Casper.prototype.open = function(location, options) {
username: httpAuthMatch[1],
password: httpAuthMatch[2]
};
this.emit('http.auth', httpAuth);
this.setHttpAuth(httpAuth.username, httpAuth.password);
}
this.emit('open', location);
......@@ -718,7 +717,7 @@ Casper.prototype.run = function(onComplete, time) {
return this;
}
this.log(f("Running suite: %d step%s", this.steps.length, this.steps.length > 1 ? "s" : ""), "info");
this.emit('run');
this.emit('run.start');
this.checker = setInterval(this.checkStep, (time ? time: 250), this, onComplete);
return this;
};
......
......@@ -55,7 +55,7 @@ var Mouse = function(casper) {
throw new Error('Unsupported mouse event type: ' + type);
}
args = Array.prototype.slice.call(args); // cast Arguments -> Array
casper.emit('casper.mouse.click', args);
casper.emit('mouse.' + type, args);
switch (args.length) {
case 0:
throw new Error('Too few arguments');
......
casper = require('casper').create()
# listening to a custom event
casper.on 'google.loaded', (title) ->
casper.echo "Google page title is #{title}"
casper.start 'http://google.com/', ->
# emitting a custom event
@emit 'google.loaded', @getTitle()
casper.run()
\ No newline at end of file
var casper = require('casper').create();
// listening to a custom event
casper.on('google.loaded', function(title) {
casper.echo('Google page title is ' + title);
});
casper.start('http://google.com/', function(self) {
// emitting a custom event
self.emit('google.loaded', self.getTitle());
});
casper.run();
\ No newline at end of file