Commit 0b240e99 0b240e9939ce922f228f5cd0d2ea6e6ce642aaec by Laurent Jouanneau

Refs #482: CasperJS should wait after the browser initialization

The call of webpage.open() (or openUrl()) is synchronous in PhantomJS,
but is asynchronous in SlimerJS (it needs to open a real window etc..).

So CasperJS should not launch the next step just after the call of
webpage.openUrl(). A flag is set to true before this call, and
then set to false when receiving the first event from the page loader.
And this flag has to be checked before to execute the next step.
1 parent cd8bcd8f
......@@ -139,6 +139,7 @@ var Casper = function Casper(options) {
this.history = [];
this.loadInProgress = false;
this.navigationRequested = false;
this.browserInitializing = false;
this.logFormats = {};
this.logLevels = ["debug", "info", "warning", "error"];
this.logStyles = {
......@@ -357,7 +358,7 @@ Casper.prototype.captureSelector = function captureSelector(targetFile, selector
*/
Casper.prototype.checkStep = function checkStep(self, onComplete) {
"use strict";
if (self.pendingWait || self.loadInProgress || self.navigationRequested) {
if (self.pendingWait || self.loadInProgress || self.navigationRequested || self.browserInitializing) {
return;
}
var step = self.steps[self.step++];
......@@ -1380,6 +1381,7 @@ Casper.prototype.open = function open(location, settings) {
// custom headers
this.page.customHeaders = utils.mergeObjects(utils.clone(baseCustomHeaders), customHeaders);
// perfom request
this.browserInitializing = true;
this.page.openUrl(this.requestUrl, {
operation: settings.method,
data: settings.data
......@@ -2382,6 +2384,7 @@ function createPage(casper) {
message += ': ' + casper.requestUrl;
casper.log(message, "warning");
casper.navigationRequested = false;
casper.browserInitializing = false;
if (utils.isFunction(casper.options.onLoadError)) {
casper.options.onLoadError.call(casper, casper, casper.requestUrl, status);
}
......@@ -2400,6 +2403,7 @@ function createPage(casper) {
page.onNavigationRequested = function onNavigationRequested(url, type, willNavigate, isMainFrame) {
casper.log(f('Navigation requested: url=%s, type=%s, willNavigate=%s, isMainFrame=%s',
url, type, willNavigate, isMainFrame), "debug");
casper.browserInitializing = false;
if (isMainFrame && casper.requestUrl !== url) {
casper.navigationRequested = true;
......