Skip to content

Commit

Permalink
Replace rootEl with browser.setAngularRoot() (angular#3996)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
heathkit authored and igniteram committed Feb 21, 2017
1 parent 2a022fe commit 691834a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/bpRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
54 changes: 46 additions & 8 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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
Expand All @@ -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;
Expand All @@ -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`.
Expand Down Expand Up @@ -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);
});
}
};

Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 691834a

Please sign in to comment.