Commit c441ee41 c441ee411c9d363a6d4b683824f04779cece5e75 by Nicolas Perriault

Merge pull request #204 from chiefcll/fix-url-change-via-javascript

Fix for when the url is changed via javascript
2 parents 46882628 dbb3dc02
......@@ -117,6 +117,7 @@ var Casper = function Casper(options) {
this.defaultWaitTimeout = 5000;
this.history = [];
this.loadInProgress = false;
this.navigationRequested = false;
this.logFormats = {};
this.logLevels = ["debug", "info", "warning", "error"];
this.logStyles = {
......@@ -316,7 +317,7 @@ Casper.prototype.captureSelector = function captureSelector(targetFile, selector
*/
Casper.prototype.checkStep = function checkStep(self, onComplete) {
"use strict";
if (self.pendingWait || self.loadInProgress) {
if (self.pendingWait || self.loadInProgress || self.navigationRequested) {
return;
}
var step = self.steps[self.step++];
......@@ -1639,6 +1640,7 @@ function createPage(casper) {
}
message += ': ' + casper.requestUrl;
casper.log(message, "warning");
casper.navigationRequested = false;
if (utils.isFunction(casper.options.onLoadError)) {
casper.options.onLoadError.call(casper, casper, casper.requestUrl, status);
}
......@@ -1668,6 +1670,9 @@ function createPage(casper) {
page.onNavigationRequested = function onNavigationRequested(url, navigationType, navigationLocked, isMainFrame) {
casper.log(f('Navigation requested: url=%s, type=%s, lock=%s, isMainFrame=%s',
url, navigationType, navigationLocked, isMainFrame), "debug");
if(isMainFrame) {
casper.navigationRequested = true;
}
casper.emit('navigation.requested', url, navigationType, navigationLocked, isMainFrame);
};
page.onPrompt = function onPrompt(message, value) {
......@@ -1702,6 +1707,7 @@ function createPage(casper) {
};
page.onUrlChanged = function onUrlChanged(url) {
casper.log(f('url changed to "%s"', url), "debug");
casper.navigationRequested = false;
casper.emit('url.changed', url);
};
casper.emit('page.created', page);
......