Skip to content
This repository has been archived by the owner on May 10, 2018. It is now read-only.

Commit

Permalink
Fix premature JS execution issue by always loading blank page (sync), f…
Browse files Browse the repository at this point in the history
…ixes #18
  • Loading branch information
uuf6429 committed Apr 25, 2017
1 parent 8cf652c commit 02a1729
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/Server/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ Electron.app.on('ready', function() {
screenshotResponse = null,
windowWillUnload = false,
windowIdNameMap = {},
captureResponse = false;
captureResponse = false,
bindServerOnce;

global.newWindowName = '';
global.DELAY_SCRIPT_RESPONSE = '{%DelayElectronScriptResponse%}';
Expand Down Expand Up @@ -346,8 +347,14 @@ Electron.app.on('ready', function() {
ResponseManager.remove(window.id);
})
.on('did-finish-load', function () {
Logger.info('Page finished loading.');
pageVisited = true;
if (bindServerOnce) {
Logger.info('Main page loaded, binding sever...');
bindServerOnce();
bindServerOnce = null;
} else {
Logger.info('Page finished loading.');
pageVisited = true;
}
})
.on('did-fail-load', function (event, errorCode, errorDescription, validatedURL, isMainFrame) {
Logger.warn('Page failed to load (error %s): %s (validatedURL: "%s", isMainFrame: %s).', errorCode, errorDescription, validatedURL, isMainFrame ? 'yes' : 'no');
Expand Down Expand Up @@ -793,17 +800,24 @@ Electron.app.on('ready', function() {
}
);

let params = /(.*):(\d+)/.exec(process.argv[2]);
if (params) {
params = {
host: params[1],
port: params[2]
};
} else {
params = {
path: process.argv[2]
};
}

server.listen(params);
bindServerOnce = function() {
let params = /(.*):(\d+)/.exec(process.argv[2]);
if (params) {
params = {
host: params[1],
port: params[2]
};
} else {
params = {
path: process.argv[2]
};
}

server.listen(params);
};

/* This will trigger a chain of events that should eventually cause
* bindServerOnce to be called and cleared (to avoid being called again).
*/
mainWindow.loadURL('about:blank;');
});
10 changes: 10 additions & 0 deletions tests/WebDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,14 @@ public function testWindowMaximize()
"Maximize failed (screen height: $screenHeight, window height: $windowHeight, original: $windowOrigHeight)"
);
}

public function testOpeningNewWindow()
{
$this->assertEquals(['frame-1'], $this->driver->getWindowNames());

$this->assertSame(9, $this->driver->evaluateScript('4 + 5'));

$this->driver->executeScript('window.open();');
$this->assertEquals(['frame-1', 'frame-2'], $this->driver->getWindowNames());
}
}

0 comments on commit 02a1729

Please sign in to comment.