Commit 93678e97 93678e9797e342fd470ad25bf2cc4269e97941ac by Nicolas Perriault

added Casper.options.onStepComplete() callback

1 parent a56aadfe
......@@ -49,6 +49,7 @@
onError: null,
onLoadError: null,
onPageInitialized: null,
onStepComplete: null,
onStepTimeout: null,
onTimeout: null,
page: null,
......@@ -612,6 +613,7 @@
runStep: function(step) {
var skipLog = isType(step.options, "object") && step.options.skipLog === true;
var stepInfo = "Step " + (this.step + 1) + "/" + this.steps.length;
var stepResult;
if (!skipLog) {
this.log(stepInfo + ' ' + this.getCurrentUrl() + ' (HTTP ' + this.currentHTTPStatus + ')', "info");
}
......@@ -630,7 +632,7 @@
}, this.options.stepTimeout, this, new Date().getTime(), this.step);
}
try {
step(this);
stepResult = step(this);
} catch (e) {
if (this.options.faultTolerant) {
this.log("Step error: " + e, "error");
......@@ -638,6 +640,9 @@
throw e;
}
}
if (isType(this.options.onStepComplete, "function")) {
this.options.onStepComplete(this, stepResult);
}
if (!skipLog) {
this.log(stepInfo + ": done in " + (new Date().getTime() - this.startTime) + "ms.", "info");
}
......
......@@ -213,6 +213,15 @@ casper.thenOpen('tests/site/global.html', function(self) {
self.test.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'global retrieved')
});
// Casper.options.onStepComplete
casper.then(function(self) {
self.options.onStepComplete = function(self, stepResult) {
self.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete');
self.options.onStepComplete = null;
};
return 'ok';
});
// History
casper
.thenOpen('tests/site/page1.html')
......