diff --git a/lib/browser.ts b/lib/browser.ts index bfb1d3c9e..210da8af6 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -134,10 +134,16 @@ function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) { arguments[i] = arguments[i].getWebElement(); } } + const run = () => { + return from[fnName].apply(from, arguments); + }; if (setupFn) { - setupFn(); + const setupResult = setupFn(); + if (setupResult && (typeof setupResult.then === 'function')) { + return setupResult.then(run); + } } - return from[fnName].apply(from, arguments); + return run(); }; }; @@ -252,13 +258,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * @type {boolean} */ set ignoreSynchronization(value) { - this.driver.controlFlow().execute(() => { - if (this.bpClient) { - logger.debug('Setting waitForAngular' + value); - this.bpClient.setSynchronization(!value); - } - }, `Set proxy synchronization to ${value}`); - this.internalIgnoreSynchronization = value; + this.waitForAngularEnabled(!value); } get ignoreSynchronization() { @@ -449,11 +449,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * Call waitForAngularEnabled() without passing a value to read the current * state without changing it. */ - waitForAngularEnabled(enabled: boolean = null): boolean { + waitForAngularEnabled(enabled: boolean = null): wdpromise.Promise { if (enabled != null) { - this.ignoreSynchronization = !enabled; + const ret = this.driver.controlFlow().execute(() => { + if (this.bpClient) { + logger.debug('Setting waitForAngular' + !enabled); + return this.bpClient.setSynchronization(enabled).then(() => { + return enabled; + }); + } + }, `Set proxy synchronization enabled to ${enabled}`); + this.internalIgnoreSynchronization = !enabled; + return ret; } - return !this.ignoreSynchronization; + return wdpromise.when(!this.ignoreSynchronization); } /** @@ -659,7 +668,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { let runWaitForAngularScript: () => wdpromise.Promise = () => { if (this.plugins_.skipAngularStability() || this.bpClient) { - return wdpromise.when(null); + return this.driver.controlFlow().execute(() => { + return wdpromise.when(null); + }, 'bpClient or plugin stability override'); } else { return this.executeAsyncScript_( clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description, @@ -1053,15 +1064,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * page has been changed. */ setLocation(url: string): wdpromise.Promise { - this.waitForAngular(); - return this - .executeScriptWithDescription( - clientSideScripts.setLocation, 'Protractor.setLocation()', this.rootEl, url) - .then((browserErr: Error) => { - if (browserErr) { - throw 'Error while navigating to \'' + url + '\' : ' + JSON.stringify(browserErr); - } - }); + return this.waitForAngular().then( + () => this.executeScriptWithDescription( + clientSideScripts.setLocation, 'Protractor.setLocation()', this.rootEl, url) + .then((browserErr: Error) => { + if (browserErr) { + throw 'Error while navigating to \'' + url + '\' : ' + + JSON.stringify(browserErr); + } + })); } /** @@ -1075,9 +1086,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * AngularJS. */ getLocationAbsUrl(): wdpromise.Promise { - this.waitForAngular(); - return this.executeScriptWithDescription( - clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', this.rootEl); + return this.waitForAngular().then( + () => this.executeScriptWithDescription( + clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', this.rootEl)); } /** @@ -1102,10 +1113,10 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { */ debugger() { // jshint debug: true - this.driver.executeScript(clientSideScripts.installInBrowser); - wdpromise.controlFlow().execute(() => { - debugger; - }, 'add breakpoint to control flow'); + return this.driver.executeScript(clientSideScripts.installInBrowser) + .then(() => wdpromise.controlFlow().execute(() => { + debugger; + }, 'add breakpoint to control flow')); } /** diff --git a/lib/clientsidescripts.js b/lib/clientsidescripts.js index e86f776fa..c741c8d7e 100644 --- a/lib/clientsidescripts.js +++ b/lib/clientsidescripts.js @@ -109,8 +109,8 @@ function getNg1Hooks(selector, injectorPlease) { return {$injector: $injector, $$testability: $$testability}; } else { return tryEl(document.body) || - trySelector('[ng-app]') || trySelector('[ng:app]') || - trySelector('[ng-controller]') || trySelector('[ng:controller]'); + trySelector('[ng-app]') || trySelector('[ng\\:app]') || + trySelector('[ng-controller]') || trySelector('[ng\\:controller]'); } }