Commit 848791c2 848791c2521f5e4bcdab8d0011811b518f2a295d by Nicolas Perriault

added "complete.error" event

- this allows a test suite to fail within a casper.run() onComplete callback
- rewritten some tests
1 parent c64cd455
...@@ -348,18 +348,22 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) { ...@@ -348,18 +348,22 @@ Casper.prototype.checkStep = function checkStep(self, onComplete) {
348 } 348 }
349 var step = self.steps[self.step++]; 349 var step = self.steps[self.step++];
350 if (utils.isFunction(step)) { 350 if (utils.isFunction(step)) {
351 self.runStep(step); 351 return self.runStep(step);
352 } else { 352 }
353 self.result.time = new Date().getTime() - self.startTime; 353 self.result.time = new Date().getTime() - self.startTime;
354 self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info"); 354 self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info");
355 clearInterval(self.checker); 355 clearInterval(self.checker);
356 self.step -= 1; 356 self.step -= 1;
357 self.emit('run.complete'); 357 self.emit('run.complete');
358 try {
358 if (utils.isFunction(onComplete)) { 359 if (utils.isFunction(onComplete)) {
359 onComplete.call(self, self); 360 onComplete.call(self, self);
360 } else if (utils.isFunction(self.options.onRunComplete)) { 361 } else if (utils.isFunction(self.options.onRunComplete)) {
361 self.options.onRunComplete.call(self, self); 362 self.options.onRunComplete.call(self, self);
362 } 363 }
364 } catch (error) {
365 self.emit('complete.error', error);
366 throw error;
363 } 367 }
364 }; 368 };
365 369
......
...@@ -184,6 +184,7 @@ var Tester = function Tester(casper, options) { ...@@ -184,6 +184,7 @@ var Tester = function Tester(casper, options) {
184 } 184 }
185 this.casper.on('event.error', errorHandler); 185 this.casper.on('event.error', errorHandler);
186 this.casper.on('step.error', errorHandler); 186 this.casper.on('step.error', errorHandler);
187 this.casper.on('complete.error', errorHandler);
187 188
188 this.casper.on('warn', function(warning) { 189 this.casper.on('warn', function(warning) {
189 if (self.currentSuite) { 190 if (self.currentSuite) {
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.test.begin('can confirm dialog', 2, function(test) { 3 casper.test.begin('can confirm dialog', 2, {
4 var received; 4 received: undefined,
5 casper.removeAllFilters('page.confirm') 5
6 casper.setFilter('page.confirm', function(message) { 6 setUp: function(test) {
7 received = message; 7 var self = this;
8 return true; 8 casper.removeAllFilters('page.confirm');
9 }); 9 casper.setFilter('page.confirm', function(message) {
10 casper.start('tests/site/confirm.html', function() { 10 self.received = message;
11 test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted'); 11 return true;
12 }); 12 });
13 casper.run(function() { 13 },
14 test.assertEquals(received, 'are you sure?', 'confirmation message is ok'); 14
15 test.done(); 15 tearDown: function(test) {
16 }); 16 casper.removeAllFilters('page.confirm');
17 },
18
19 test: function(test) {
20 var self = this;
21 casper.start('tests/site/confirm.html', function() {
22 test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
23 }).run(function() {
24 test.assertEquals(self.received, 'are you sure?', 'confirmation message is ok');
25 test.done();
26 });
27 }
17 }); 28 });
18 29
19 casper.test.begin('can cancel dialog', 1, function(test) { 30 casper.test.begin('can cancel dialog', {
20 casper.removeAllFilters('page.confirm') 31 received: undefined,
21 casper.setFilter('page.confirm', function(message) { 32
22 return false; 33 setUp: function(test) {
23 }); 34 var self = this;
24 casper.start('tests/site/confirm.html', function() { 35 casper.removeAllFilters('page.confirm');
25 test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled'); 36 casper.setFilter('page.confirm', function(message) {
26 }); 37 return false;
27 casper.run(function() { 38 });
28 test.done(); 39 },
29 }); 40
41 tearDown: function(test) {
42 casper.removeAllFilters('page.confirm');
43 },
44
45 test: function(test) {
46 var self = this;
47 casper.start('tests/site/confirm.html', function() {
48 test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
49 }).run(function() {
50 test.done();
51 });
52 }
30 }); 53 });
......