diff --git a/tests/_base.js b/tests/_base.js index 5a23b6f27..0e6ebdd13 100644 --- a/tests/_base.js +++ b/tests/_base.js @@ -119,9 +119,6 @@ exports.mocha = function (_module, options) { yield this.client.waitUntilWindowLoaded(); - // wait a small amount of time to ensure main app window is ready with data - yield Q.delay(8000); - // console.log(this.app.chromeDriver.logLines); /* @@ -131,6 +128,26 @@ exports.mocha = function (_module, options) { this[key] = genomatic.bind(Utils[key], this); } + // Loop over windows trying to select Main Window + let app = this; + let selectMainWindow = function* (mainWindowSearch) { + let windowHandles = (yield app.client.windowHandles()).value; + + for (let handle in windowHandles) { + yield app.client.window(windowHandles[handle]); + const windowUrl = yield app.client.getUrl(); + const isMainWindow = mainWindowSearch.test(windowUrl); + if (isMainWindow) return true; + } + + // not main window. try again after 1 second. + yield Q.delay(1000); + yield selectMainWindow(mainWindowSearch); + } + + const mainWindowSearch = (options.app === 'wallet') ? /^file:\/\/\/$/ : /interface\/index\.html$/; + yield selectMainWindow(mainWindowSearch); + this.mainWindowHandle = (yield this.client.windowHandle()).value; },