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

Commit

Permalink
feat(browser): chain some promises in lib/browser.ts + return promi…
Browse files Browse the repository at this point in the history
…se from `waitForAngularEnabled` (#4021)

Minor breaking change since `waitForAngularEnabled` no longer returns a boolean

Part of #3904

Chaining `browser.get` has proved surprisingly complex, so I'll do that in a different PR

Also fixed a minor bug in `lib/clientsidescripts.js` while debuging
  • Loading branch information
sjelin committed Jan 27, 2017
1 parent af635fa commit 33393ca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 31 deletions.
69 changes: 40 additions & 29 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) {
arguments[i] = arguments[i].getWebElement();
}
}
const run = () => {
return from[fnName].apply(from, arguments);
};
if (setupFn) {
setupFn();
const setupResult = setupFn();
if (setupResult && (typeof setupResult.then === 'function')) {
return setupResult.then(run);
}
}
return from[fnName].apply(from, arguments);
return run();
};
};

Expand Down Expand Up @@ -287,13 +293,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* @type {boolean}
*/
set ignoreSynchronization(value) {
this.driver.controlFlow().execute(() => {
if (this.bpClient) {
logger.debug('Setting waitForAngular' + value);
return this.bpClient.setWaitEnabled(!value);
}
}, `Set proxy synchronization to ${value}`);
this.internalIgnoreSynchronization = value;
this.waitForAngularEnabled(!value);
}

get ignoreSynchronization() {
Expand Down Expand Up @@ -484,11 +484,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* Call waitForAngularEnabled() without passing a value to read the current
* state without changing it.
*/
waitForAngularEnabled(enabled: boolean = null): boolean {
waitForAngularEnabled(enabled: boolean = null): wdpromise.Promise<boolean> {
if (enabled != null) {
this.ignoreSynchronization = !enabled;
const ret = this.driver.controlFlow().execute(() => {
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;
}
return !this.ignoreSynchronization;
return wdpromise.when(!this.ignoreSynchronization);
}

/**
Expand Down Expand Up @@ -694,7 +703,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {

let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
if (this.plugins_.skipAngularStability() || this.bpClient) {
return wdpromise.when(null);
return this.driver.controlFlow().execute(() => {
return wdpromise.when(null);
}, 'bpClient or plugin stability override');
} else {
// Need to wrap this so that we read rootEl in the control flow, not synchronously.
return this.angularAppRoot().then((rootEl: string) => {
Expand Down Expand Up @@ -1091,15 +1102,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* page has been changed.
*/
setLocation(url: string): wdpromise.Promise<any> {
this.waitForAngular();
return this
.executeScriptWithDescription(
clientSideScripts.setLocation, 'Protractor.setLocation()', this.rootEl, url)
.then((browserErr: Error) => {
if (browserErr) {
throw 'Error while navigating to \'' + url + '\' : ' + JSON.stringify(browserErr);
}
});
return this.waitForAngular().then(
() => this.executeScriptWithDescription(
clientSideScripts.setLocation, 'Protractor.setLocation()', this.rootEl, url)
.then((browserErr: Error) => {
if (browserErr) {
throw 'Error while navigating to \'' + url + '\' : ' +
JSON.stringify(browserErr);
}
}));
}

/**
Expand All @@ -1113,9 +1124,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* AngularJS.
*/
getLocationAbsUrl(): wdpromise.Promise<any> {
this.waitForAngular();
return this.executeScriptWithDescription(
clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', this.rootEl);
return this.waitForAngular().then(
() => this.executeScriptWithDescription(
clientSideScripts.getLocationAbsUrl, 'Protractor.getLocationAbsUrl()', this.rootEl));
}

/**
Expand All @@ -1140,10 +1151,10 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
*/
debugger() {
// jshint debug: true
this.driver.executeScript(clientSideScripts.installInBrowser);
wdpromise.controlFlow().execute(() => {
debugger;
}, 'add breakpoint to control flow');
return this.driver.executeScript(clientSideScripts.installInBrowser)
.then(() => wdpromise.controlFlow().execute(() => {
debugger;
}, 'add breakpoint to control flow'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ function getNg1Hooks(selector, injectorPlease) {
return {$injector: $injector, $$testability: $$testability};
} else {
return tryEl(document.body) ||
trySelector('[ng-app]') || trySelector('[ng:app]') ||
trySelector('[ng-controller]') || trySelector('[ng:controller]');
trySelector('[ng-app]') || trySelector('[ng\\:app]') ||
trySelector('[ng-controller]') || trySelector('[ng\\:controller]');
}
}

Expand Down

0 comments on commit 33393ca

Please sign in to comment.