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

Commit

Permalink
fix(restart): preserve waitForAngularEnabled on restart and add promi…
Browse files Browse the repository at this point in the history
…se chaining (#4047)

I noticed I missed `waitForAngularEnabled` in
#4037.  This commit fixed that.

While I was at it I fixed a minor error where the promises implicitly created by
setting `rootEl` and `ignoreSynchronization` weren't getting chained properly.

Also fixed minor (so minor I think it was impossible to trigger) where
browser.plugins_ could be undefined.
  • Loading branch information
sjelin authored and cnishina committed Feb 1, 2017
1 parent 5899b67 commit f9bee84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
25 changes: 14 additions & 11 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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<boolean> {
waitForAngularEnabled(enabled: boolean|wdpromise.Promise<boolean> = null):
wdpromise.Promise<boolean> {
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;
Expand Down
11 changes: 7 additions & 4 deletions lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>
};

if (parentBrowser) {
Expand All @@ -249,16 +250,15 @@ 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(
driver, initProperties.baseUrl, initProperties.rootElement,
initProperties.untrackOutstandingTimeouts, blockingProxyUrl);

browser_.params = initProperties.params;
if (plugins) {
browser_.plugins_ = plugins;
}
browser_.plugins_ = plugins || new Plugins({});
if (initProperties.getPageTimeout) {
browser_.getPageTimeout = initProperties.getPageTimeout;
}
Expand All @@ -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);
})
Expand Down

0 comments on commit f9bee84

Please sign in to comment.