refactored some events; added customevents sample
Showing
4 changed files
with
27 additions
and
4 deletions
... | @@ -208,7 +208,7 @@ Casper.prototype.checkStep = function(self, onComplete) { | ... | @@ -208,7 +208,7 @@ Casper.prototype.checkStep = function(self, onComplete) { |
208 | self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info"); | 208 | self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info"); |
209 | self.page.content = ''; // avoid having previously loaded DOM contents being still active (refs #34) | 209 | self.page.content = ''; // avoid having previously loaded DOM contents being still active (refs #34) |
210 | clearInterval(self.checker); | 210 | clearInterval(self.checker); |
211 | self.emit('step.complete'); | 211 | self.emit('run.complete'); |
212 | if (utils.isFunction(onComplete)) { | 212 | if (utils.isFunction(onComplete)) { |
213 | try { | 213 | try { |
214 | onComplete.call(self, self); | 214 | onComplete.call(self, self); |
... | @@ -653,7 +653,6 @@ Casper.prototype.open = function(location, options) { | ... | @@ -653,7 +653,6 @@ Casper.prototype.open = function(location, options) { |
653 | username: httpAuthMatch[1], | 653 | username: httpAuthMatch[1], |
654 | password: httpAuthMatch[2] | 654 | password: httpAuthMatch[2] |
655 | }; | 655 | }; |
656 | this.emit('http.auth', httpAuth); | ||
657 | this.setHttpAuth(httpAuth.username, httpAuth.password); | 656 | this.setHttpAuth(httpAuth.username, httpAuth.password); |
658 | } | 657 | } |
659 | this.emit('open', location); | 658 | this.emit('open', location); |
... | @@ -718,7 +717,7 @@ Casper.prototype.run = function(onComplete, time) { | ... | @@ -718,7 +717,7 @@ Casper.prototype.run = function(onComplete, time) { |
718 | return this; | 717 | return this; |
719 | } | 718 | } |
720 | this.log(f("Running suite: %d step%s", this.steps.length, this.steps.length > 1 ? "s" : ""), "info"); | 719 | this.log(f("Running suite: %d step%s", this.steps.length, this.steps.length > 1 ? "s" : ""), "info"); |
721 | this.emit('run'); | 720 | this.emit('run.start'); |
722 | this.checker = setInterval(this.checkStep, (time ? time: 250), this, onComplete); | 721 | this.checker = setInterval(this.checkStep, (time ? time: 250), this, onComplete); |
723 | return this; | 722 | return this; |
724 | }; | 723 | }; | ... | ... |
... | @@ -55,7 +55,7 @@ var Mouse = function(casper) { | ... | @@ -55,7 +55,7 @@ var Mouse = function(casper) { |
55 | throw new Error('Unsupported mouse event type: ' + type); | 55 | throw new Error('Unsupported mouse event type: ' + type); |
56 | } | 56 | } |
57 | args = Array.prototype.slice.call(args); // cast Arguments -> Array | 57 | args = Array.prototype.slice.call(args); // cast Arguments -> Array |
58 | casper.emit('casper.mouse.click', args); | 58 | casper.emit('mouse.' + type, args); |
59 | switch (args.length) { | 59 | switch (args.length) { |
60 | case 0: | 60 | case 0: |
61 | throw new Error('Too few arguments'); | 61 | throw new Error('Too few arguments'); | ... | ... |
samples/customevents.coffee
0 → 100644
1 | casper = require('casper').create() | ||
2 | |||
3 | # listening to a custom event | ||
4 | casper.on 'google.loaded', (title) -> | ||
5 | casper.echo "Google page title is #{title}" | ||
6 | |||
7 | casper.start 'http://google.com/', -> | ||
8 | # emitting a custom event | ||
9 | @emit 'google.loaded', @getTitle() | ||
10 | |||
11 | casper.run() | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
samples/customevents.js
0 → 100644
1 | var casper = require('casper').create(); | ||
2 | |||
3 | // listening to a custom event | ||
4 | casper.on('google.loaded', function(title) { | ||
5 | casper.echo('Google page title is ' + title); | ||
6 | }); | ||
7 | |||
8 | casper.start('http://google.com/', function(self) { | ||
9 | // emitting a custom event | ||
10 | self.emit('google.loaded', self.getTitle()); | ||
11 | }); | ||
12 | |||
13 | casper.run(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment