diff --git a/lib/browser.ts b/lib/browser.ts index 27d65fab0..1d6666e85 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -216,6 +216,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * tests to become flaky. This should be used only when necessary, such as * when a page continuously polls an API using $timeout. * + * Initialized to `false` by the runner. + * * This property is deprecated - please use waitForAngularEnabled instead. * * @deprecated @@ -355,8 +357,6 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { this.$ = build$(this.element, By); this.$$ = build$$(this.element, By); this.baseUrl = opt_baseUrl || ''; - this.angularAppRoot(opt_rootElement || ''); - this.ignoreSynchronization = false; this.getPageTimeout = DEFAULT_GET_PAGE_TIMEOUT; this.params = {}; this.resetUrl = DEFAULT_RESET_URL; @@ -379,8 +379,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { ng12Hybrid_ = ng12Hybrid; } }); - this.ready = this.driver.controlFlow() - .execute(() => { + this.ready = this.angularAppRoot(opt_rootElement || '') + .then(() => { return this.driver.getSession(); }) .then((session: Session) => { @@ -413,15 +413,18 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * Call waitForAngularEnabled() without passing a value to read the current * state without changing it. */ - waitForAngularEnabled(enabled: boolean = null): wdpromise.Promise { + waitForAngularEnabled(enabled: boolean|wdpromise.Promise = null): + wdpromise.Promise { if (enabled != null) { const ret = this.driver.controlFlow().execute(() => { - if (this.bpClient) { - logger.debug('Setting waitForAngular' + !enabled); - return this.bpClient.setWaitEnabled(enabled).then(() => { - return enabled; - }); - } + return wdpromise.when(enabled).then((enabled: boolean) => { + if (this.bpClient) { + logger.debug('Setting waitForAngular' + !enabled); + return this.bpClient.setWaitEnabled(enabled).then(() => { + return enabled; + }); + } + }); }, `Set proxy synchronization enabled to ${enabled}`); this.internalIgnoreSynchronization = !enabled; return ret; diff --git a/lib/runner.ts b/lib/runner.ts index 677b5fd0a..359e7428c 100644 --- a/lib/runner.ts +++ b/lib/runner.ts @@ -237,7 +237,8 @@ export class Runner extends EventEmitter { getPageTimeout: config.getPageTimeout, allScriptsTimeout: config.allScriptsTimeout, debuggerServerPort: config.debuggerServerPort, - ng12Hybrid: config.ng12Hybrid + ng12Hybrid: config.ng12Hybrid, + waitForAngularEnabled: true as boolean | wdpromise.Promise }; if (parentBrowser) { @@ -249,6 +250,7 @@ export class Runner extends EventEmitter { initProperties.allScriptsTimeout = parentBrowser.allScriptsTimeout; initProperties.debuggerServerPort = parentBrowser.debuggerServerPort; initProperties.ng12Hybrid = parentBrowser.ng12Hybrid; + initProperties.waitForAngularEnabled = parentBrowser.waitForAngularEnabled(); } let browser_ = new ProtractorBrowser( @@ -256,9 +258,7 @@ export class Runner extends EventEmitter { initProperties.untrackOutstandingTimeouts, blockingProxyUrl); browser_.params = initProperties.params; - if (plugins) { - browser_.plugins_ = plugins; - } + browser_.plugins_ = plugins || new Plugins({}); if (initProperties.getPageTimeout) { browser_.getPageTimeout = initProperties.getPageTimeout; } @@ -274,6 +274,9 @@ export class Runner extends EventEmitter { browser_.ready = browser_.ready + .then(() => { + return browser_.waitForAngularEnabled(initProperties.waitForAngularEnabled); + }) .then(() => { return driver.manage().timeouts().setScriptTimeout(initProperties.allScriptsTimeout); })