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) {
}
var step = self.steps[self.step++];
if (utils.isFunction(step)) {
self.runStep(step);
} else {
self.result.time = new Date().getTime() - self.startTime;
self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info");
clearInterval(self.checker);
self.step -= 1;
self.emit('run.complete');
return self.runStep(step);
}
self.result.time = new Date().getTime() - self.startTime;
self.log(f("Done %s steps in %dms", self.steps.length, self.result.time), "info");
clearInterval(self.checker);
self.step -= 1;
self.emit('run.complete');
try {
if (utils.isFunction(onComplete)) {
onComplete.call(self, self);
} else if (utils.isFunction(self.options.onRunComplete)) {
self.options.onRunComplete.call(self, self);
}
} catch (error) {
self.emit('complete.error', error);
throw error;
}
};
......
......@@ -184,6 +184,7 @@ var Tester = function Tester(casper, options) {
}
this.casper.on('event.error', errorHandler);
this.casper.on('step.error', errorHandler);
this.casper.on('complete.error', errorHandler);
this.casper.on('warn', function(warning) {
if (self.currentSuite) {
......
/*global casper*/
/*jshint strict:false*/
casper.test.begin('can confirm dialog', 2, function(test) {
var received;
casper.removeAllFilters('page.confirm')
casper.setFilter('page.confirm', function(message) {
received = message;
return true;
});
casper.start('tests/site/confirm.html', function() {
test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
});
casper.run(function() {
test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
test.done();
});
casper.test.begin('can confirm dialog', 2, {
received: undefined,
setUp: function(test) {
var self = this;
casper.removeAllFilters('page.confirm');
casper.setFilter('page.confirm', function(message) {
self.received = message;
return true;
});
},
tearDown: function(test) {
casper.removeAllFilters('page.confirm');
},
test: function(test) {
var self = this;
casper.start('tests/site/confirm.html', function() {
test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
}).run(function() {
test.assertEquals(self.received, 'are you sure?', 'confirmation message is ok');
test.done();
});
}
});
casper.test.begin('can cancel dialog', 1, function(test) {
casper.removeAllFilters('page.confirm')
casper.setFilter('page.confirm', function(message) {
return false;
});
casper.start('tests/site/confirm.html', function() {
test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
});
casper.run(function() {
test.done();
});
casper.test.begin('can cancel dialog', {
received: undefined,
setUp: function(test) {
var self = this;
casper.removeAllFilters('page.confirm');
casper.setFilter('page.confirm', function(message) {
return false;
});
},
tearDown: function(test) {
casper.removeAllFilters('page.confirm');
},
test: function(test) {
var self = this;
casper.start('tests/site/confirm.html', function() {
test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
}).run(function() {
test.done();
});
}
});
......