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

Commit f9bee84

Browse files
sjelincnishina
authored andcommitted
fix(restart): preserve waitForAngularEnabled on restart and add promise 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.
1 parent 5899b67 commit f9bee84

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

lib/browser.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
216216
* tests to become flaky. This should be used only when necessary, such as
217217
* when a page continuously polls an API using $timeout.
218218
*
219+
* Initialized to `false` by the runner.
220+
*
219221
* This property is deprecated - please use waitForAngularEnabled instead.
220222
*
221223
* @deprecated
@@ -355,8 +357,6 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
355357
this.$ = build$(this.element, By);
356358
this.$$ = build$$(this.element, By);
357359
this.baseUrl = opt_baseUrl || '';
358-
this.angularAppRoot(opt_rootElement || '');
359-
this.ignoreSynchronization = false;
360360
this.getPageTimeout = DEFAULT_GET_PAGE_TIMEOUT;
361361
this.params = {};
362362
this.resetUrl = DEFAULT_RESET_URL;
@@ -379,8 +379,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
379379
ng12Hybrid_ = ng12Hybrid;
380380
}
381381
});
382-
this.ready = this.driver.controlFlow()
383-
.execute(() => {
382+
this.ready = this.angularAppRoot(opt_rootElement || '')
383+
.then(() => {
384384
return this.driver.getSession();
385385
})
386386
.then((session: Session) => {
@@ -413,15 +413,18 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
413413
* Call waitForAngularEnabled() without passing a value to read the current
414414
* state without changing it.
415415
*/
416-
waitForAngularEnabled(enabled: boolean = null): wdpromise.Promise<boolean> {
416+
waitForAngularEnabled(enabled: boolean|wdpromise.Promise<boolean> = null):
417+
wdpromise.Promise<boolean> {
417418
if (enabled != null) {
418419
const ret = this.driver.controlFlow().execute(() => {
419-
if (this.bpClient) {
420-
logger.debug('Setting waitForAngular' + !enabled);
421-
return this.bpClient.setWaitEnabled(enabled).then(() => {
422-
return enabled;
423-
});
424-
}
420+
return wdpromise.when(enabled).then((enabled: boolean) => {
421+
if (this.bpClient) {
422+
logger.debug('Setting waitForAngular' + !enabled);
423+
return this.bpClient.setWaitEnabled(enabled).then(() => {
424+
return enabled;
425+
});
426+
}
427+
});
425428
}, `Set proxy synchronization enabled to ${enabled}`);
426429
this.internalIgnoreSynchronization = !enabled;
427430
return ret;

lib/runner.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export class Runner extends EventEmitter {
237237
getPageTimeout: config.getPageTimeout,
238238
allScriptsTimeout: config.allScriptsTimeout,
239239
debuggerServerPort: config.debuggerServerPort,
240-
ng12Hybrid: config.ng12Hybrid
240+
ng12Hybrid: config.ng12Hybrid,
241+
waitForAngularEnabled: true as boolean | wdpromise.Promise<boolean>
241242
};
242243

243244
if (parentBrowser) {
@@ -249,16 +250,15 @@ export class Runner extends EventEmitter {
249250
initProperties.allScriptsTimeout = parentBrowser.allScriptsTimeout;
250251
initProperties.debuggerServerPort = parentBrowser.debuggerServerPort;
251252
initProperties.ng12Hybrid = parentBrowser.ng12Hybrid;
253+
initProperties.waitForAngularEnabled = parentBrowser.waitForAngularEnabled();
252254
}
253255

254256
let browser_ = new ProtractorBrowser(
255257
driver, initProperties.baseUrl, initProperties.rootElement,
256258
initProperties.untrackOutstandingTimeouts, blockingProxyUrl);
257259

258260
browser_.params = initProperties.params;
259-
if (plugins) {
260-
browser_.plugins_ = plugins;
261-
}
261+
browser_.plugins_ = plugins || new Plugins({});
262262
if (initProperties.getPageTimeout) {
263263
browser_.getPageTimeout = initProperties.getPageTimeout;
264264
}
@@ -274,6 +274,9 @@ export class Runner extends EventEmitter {
274274

275275
browser_.ready =
276276
browser_.ready
277+
.then(() => {
278+
return browser_.waitForAngularEnabled(initProperties.waitForAngularEnabled);
279+
})
277280
.then(() => {
278281
return driver.manage().timeouts().setScriptTimeout(initProperties.allScriptsTimeout);
279282
})

0 commit comments

Comments
 (0)