Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 4a59412

Browse files
authored
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.
1 parent ccf02ab commit 4a59412

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

lib/bpRunner.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export class BlockingProxyRunner {
1919
this.checkSupportedConfig();
2020

2121
let args = [
22-
'--fork', '--seleniumAddress', this.config.seleniumAddress, '--rootElement',
23-
this.config.rootElement
22+
'--fork',
23+
'--seleniumAddress',
24+
this.config.seleniumAddress,
2425
];
2526
this.bpProcess = fork(BP_PATH, args, {silent: true});
2627
logger.info('Starting BlockingProxy with args: ' + args.toString());

lib/browser.ts

+46-8
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,44 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
235235
* 'body' but if your ng-app is on a subsection of the page it may be
236236
* a subelement.
237237
*
238+
* This property is deprecated - please use angularAppRoot() instead.
239+
*
240+
* @deprecated
238241
* @type {string}
239242
*/
240-
rootEl: string;
243+
set rootEl(value: string) {
244+
this.angularAppRoot(value);
245+
}
246+
247+
get rootEl() {
248+
return this.internalRootEl;
249+
}
250+
251+
private internalRootEl: string;
252+
253+
/**
254+
* Set the css selector for an element on which to find Angular. This is usually
255+
* 'body' but if your ng-app is on a subsection of the page it may be
256+
* a subelement.
257+
*
258+
* The change will be made within WebDriver's control flow, so that commands after
259+
* this method is called use the new app root. Pass nothing to get a promise that
260+
* resolves to the value of the selector.
261+
*
262+
* @param {string} The new selector.
263+
* @returns A promise that resolves with the value of the selector.
264+
*/
265+
angularAppRoot(value: string = null): wdpromise.Promise<string> {
266+
return this.driver.controlFlow().execute(() => {
267+
if (value != null) {
268+
if (this.bpClient) {
269+
return this.bpClient.setWaitParams(value).then(() => this.internalRootEl);
270+
}
271+
this.internalRootEl = value;
272+
return this.internalRootEl;
273+
}
274+
}, `Set angular root selector to ${value}`);
275+
}
241276

242277
/**
243278
* If true, Protractor will not attempt to synchronize with the page before
@@ -255,7 +290,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
255290
this.driver.controlFlow().execute(() => {
256291
if (this.bpClient) {
257292
logger.debug('Setting waitForAngular' + value);
258-
this.bpClient.setSynchronization(!value);
293+
return this.bpClient.setWaitEnabled(!value);
259294
}
260295
}, `Set proxy synchronization to ${value}`);
261296
this.internalIgnoreSynchronization = value;
@@ -265,7 +300,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
265300
return this.internalIgnoreSynchronization;
266301
}
267302

268-
internalIgnoreSynchronization: boolean;
303+
private internalIgnoreSynchronization: boolean;
269304

270305
/**
271306
* Timeout in milliseconds to wait for pages to load when calling `get`.
@@ -570,9 +605,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
570605
if (this.plugins_.skipAngularStability() || this.bpClient) {
571606
return wdpromise.fulfilled();
572607
} else {
573-
return this.executeAsyncScript_(
574-
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description,
575-
this.rootEl);
608+
// Need to wrap this so that we read rootEl in the control flow, not synchronously.
609+
return this.angularAppRoot().then((rootEl: string) => {
610+
return this.executeAsyncScript_(
611+
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description,
612+
rootEl);
613+
});
576614
}
577615
};
578616

@@ -794,7 +832,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
794832

795833
if (this.bpClient) {
796834
this.driver.controlFlow().execute(() => {
797-
return this.bpClient.setSynchronization(false);
835+
return this.bpClient.setWaitEnabled(false);
798836
});
799837
}
800838

@@ -902,7 +940,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
902940

903941
if (this.bpClient) {
904942
this.driver.controlFlow().execute(() => {
905-
return this.bpClient.setSynchronization(!this.internalIgnoreSynchronization);
943+
return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
906944
});
907945
}
908946

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@types/node": "^6.0.46",
1616
"@types/q": "^0.0.32",
1717
"@types/selenium-webdriver": "~2.53.39",
18-
"blocking-proxy": "0.0.2",
18+
"blocking-proxy": "0.0.3",
1919
"chalk": "^1.1.3",
2020
"glob": "^7.0.3",
2121
"jasmine": "2.4.1",

0 commit comments

Comments
 (0)