From 691834a38e92d399ec5b470bab80405e611fad99 Mon Sep 17 00:00:00 2001 From: mgiambalvo Date: Thu, 26 Jan 2017 14:36:40 -0800 Subject: [PATCH] Replace rootEl with browser.setAngularRoot() (#3996) Replace browser.rootEl with browser.setAngularRoot(), which changes the root element in a promise on the control flow. Note that browser.rootEl will immediately return the current value, but browser.setAngularRoot() will return a promise that resolves during the next step in the control flow. Also update to BlockingProxy 0.0.3, which allows changing rootSelector. --- lib/bpRunner.ts | 5 +++-- lib/browser.ts | 54 +++++++++++++++++++++++++++++++++++++++++-------- package.json | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/lib/bpRunner.ts b/lib/bpRunner.ts index bfab4514c..d0b68ccd7 100644 --- a/lib/bpRunner.ts +++ b/lib/bpRunner.ts @@ -19,8 +19,9 @@ export class BlockingProxyRunner { this.checkSupportedConfig(); let args = [ - '--fork', '--seleniumAddress', this.config.seleniumAddress, '--rootElement', - this.config.rootElement + '--fork', + '--seleniumAddress', + this.config.seleniumAddress, ]; this.bpProcess = fork(BP_PATH, args, {silent: true}); logger.info('Starting BlockingProxy with args: ' + args.toString()); diff --git a/lib/browser.ts b/lib/browser.ts index 97065f000..e9faf9753 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -235,9 +235,44 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * 'body' but if your ng-app is on a subsection of the page it may be * a subelement. * + * This property is deprecated - please use angularAppRoot() instead. + * + * @deprecated * @type {string} */ - rootEl: string; + set rootEl(value: string) { + this.angularAppRoot(value); + } + + get rootEl() { + return this.internalRootEl; + } + + private internalRootEl: string; + + /** + * Set the css selector for an element on which to find Angular. This is usually + * 'body' but if your ng-app is on a subsection of the page it may be + * a subelement. + * + * The change will be made within WebDriver's control flow, so that commands after + * this method is called use the new app root. Pass nothing to get a promise that + * resolves to the value of the selector. + * + * @param {string} The new selector. + * @returns A promise that resolves with the value of the selector. + */ + angularAppRoot(value: string = null): wdpromise.Promise { + return this.driver.controlFlow().execute(() => { + if (value != null) { + if (this.bpClient) { + return this.bpClient.setWaitParams(value).then(() => this.internalRootEl); + } + this.internalRootEl = value; + return this.internalRootEl; + } + }, `Set angular root selector to ${value}`); + } /** * If true, Protractor will not attempt to synchronize with the page before @@ -255,7 +290,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { this.driver.controlFlow().execute(() => { if (this.bpClient) { logger.debug('Setting waitForAngular' + value); - this.bpClient.setSynchronization(!value); + return this.bpClient.setWaitEnabled(!value); } }, `Set proxy synchronization to ${value}`); this.internalIgnoreSynchronization = value; @@ -265,7 +300,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { return this.internalIgnoreSynchronization; } - internalIgnoreSynchronization: boolean; + private internalIgnoreSynchronization: boolean; /** * Timeout in milliseconds to wait for pages to load when calling `get`. @@ -570,9 +605,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { if (this.plugins_.skipAngularStability() || this.bpClient) { return wdpromise.fulfilled(); } else { - return this.executeAsyncScript_( - clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description, - this.rootEl); + // Need to wrap this so that we read rootEl in the control flow, not synchronously. + return this.angularAppRoot().then((rootEl: string) => { + return this.executeAsyncScript_( + clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description, + rootEl); + }); } }; @@ -794,7 +832,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { if (this.bpClient) { this.driver.controlFlow().execute(() => { - return this.bpClient.setSynchronization(false); + return this.bpClient.setWaitEnabled(false); }); } @@ -902,7 +940,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { if (this.bpClient) { this.driver.controlFlow().execute(() => { - return this.bpClient.setSynchronization(!this.internalIgnoreSynchronization); + return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization); }); } diff --git a/package.json b/package.json index 7ef0226a7..9f59c5614 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@types/node": "^6.0.46", "@types/q": "^0.0.32", "@types/selenium-webdriver": "~2.53.39", - "blocking-proxy": "0.0.2", + "blocking-proxy": "0.0.3", "chalk": "^1.1.3", "glob": "^7.0.3", "jasmine": "2.4.1",