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

feat(browser): chain some promises in lib/browser.ts + return promi… #4021

Merged
merged 1 commit into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -252,13 +258,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* @type {boolean}
*/
set ignoreSynchronization(value) {
this.driver.controlFlow().execute(() => {
if (this.bpClient) {
logger.debug('Setting waitForAngular' + value);
this.bpClient.setSynchronization(!value);
}
}, `Set proxy synchronization to ${value}`);
this.internalIgnoreSynchronization = value;
this.waitForAngularEnabled(!value);
}

get ignoreSynchronization() {
Expand Down Expand Up @@ -449,11 +449,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.setSynchronization(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 @@ -659,7 +668,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 {
return this.executeAsyncScript_(
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description,
Expand Down Expand Up @@ -1053,15 +1064,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 @@ -1075,9 +1086,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 @@ -1102,10 +1113,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]') ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned something

trySelector('[ng-controller]') || trySelector('[ng\\:controller]');
}
}

Expand Down