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

Commit

Permalink
fix - remove control flow from waitForAngularEnabled, waitForAngular,…
Browse files Browse the repository at this point in the history
… and angularAppRoot

- Enabled the driverProviderLocal tests
- Remove auto unwrap test for a WebElement. Reference PR #3471
  • Loading branch information
cnishina committed Nov 14, 2018
1 parent 8796ad8 commit 39e02d1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 57 deletions.
78 changes: 30 additions & 48 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,18 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* 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|webdriver.promise.Promise<string>} value The new selector.
* @param {string|webdriver.promise.Promise<string>} valuePromise The new selector.
* @returns A promise that resolves with the value of the selector.
*/
angularAppRoot(value: string|wdpromise.Promise<string> = null): wdpromise.Promise<string> {
return this.driver.controlFlow().execute(() => {
if (value != null) {
return wdpromise.when(value).then((value: string) => {
this.internalRootEl = value;
if (this.bpClient) {
const bpCommandPromise = this.bpClient.setWaitParams(value);
// Convert to webdriver promise as best as possible
return wdpromise.when(bpCommandPromise as any).then(() => this.internalRootEl);
}
return this.internalRootEl;
});
async angularAppRoot(valuePromise: string|wdpromise.Promise<string> = null): Promise<string> {
if (valuePromise != null) {
const value = await Promise.resolve(valuePromise);
this.internalRootEl = value;
if (this.bpClient) {
await this.bpClient.setWaitParams(value);
}
return wdpromise.when(this.internalRootEl);
}, `Set angular root selector to ${value}`);
}
return this.internalRootEl;
}

/**
Expand Down Expand Up @@ -417,23 +411,17 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* Call waitForAngularEnabled() without passing a value to read the current
* state without changing it.
*/
waitForAngularEnabled(enabled: boolean|wdpromise.Promise<boolean> = null):
wdpromise.Promise<boolean> {
if (enabled != null) {
const ret = this.driver.controlFlow().execute(() => {
return wdpromise.when(enabled).then((enabled: boolean) => {
if (this.bpClient) {
logger.debug('Setting waitForAngular' + !enabled);
const bpCommandPromise = this.bpClient.setWaitEnabled(enabled);
// Convert to webdriver promise as best as possible
return wdpromise.when(bpCommandPromise as any).then(() => enabled);
}
});
}, `Set proxy synchronization enabled to ${enabled}`);
async waitForAngularEnabled(enabledPromise: boolean|wdpromise.Promise<boolean> = null):
Promise<boolean> {
if (enabledPromise != null) {
const enabled = await Promise.resolve(enabledPromise);
if (this.bpClient) {
logger.debug('Setting waitForAngular' + !enabled);
await this.bpClient.setWaitEnabled(enabled);
}
this.internalIgnoreSynchronization = !enabled;
return ret;
}
return wdpromise.when(!this.ignoreSynchronization);
return !this.ignoreSynchronization;
}

/**
Expand Down Expand Up @@ -602,15 +590,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* @template T
*/
private executeAsyncScript_(script: string|Function, description: string, ...scriptArgs: any[]):
wdpromise.Promise<any> {
Promise<any> {
if (typeof script === 'function') {
script = 'return (' + script + ').apply(null, arguments);';
}
return this.driver.schedule(
new Command(CommandName.EXECUTE_ASYNC_SCRIPT)
.setParameter('script', script)
.setParameter('args', scriptArgs),
description);
new Command(CommandName.EXECUTE_ASYNC_SCRIPT)
.setParameter('script', script)
.setParameter('args', scriptArgs),
description) as Promise<any>;
}

/**
Expand All @@ -624,26 +612,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* @returns {!webdriver.promise.Promise} A promise that will resolve to the
* scripts return value.
*/
waitForAngular(opt_description?: string): wdpromise.Promise<any> {
async waitForAngular(opt_description?: string): Promise<any> {
let description = opt_description ? ' - ' + opt_description : '';
if (this.ignoreSynchronization) {
return this.driver.controlFlow().execute(() => {
return true;
}, 'Ignore Synchronization Protractor.waitForAngular()');
return Promise.resolve(true);
}

let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
let runWaitForAngularScript = async(): Promise<any> => {
if (this.plugins_.skipAngularStability() || this.bpClient) {
return this.driver.controlFlow().execute(() => {
return wdpromise.when(null);
}, 'bpClient or plugin stability override');
return Promise.resolve(null);
} else {
// 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);
});
let rootEl = await this.angularAppRoot();
return this.executeAsyncScript_(
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description, rootEl);
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export abstract class DriverProvider {
if (driver.getSession() !== undefined) {
const session = await driver.getSession();
if (session) {
return driver.quit();
return await driver.quit();
}
}
} catch (_) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"pretest": "gulp pretest",
"start": "cd testapp && npm start",
"test": "node scripts/test.js",
"tsc": "tsc",
"website": "cd website && npm start",
"compile_to_es5": "gulp compile_to_es5"
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var passingTests = [
'node built/cli.js spec/interactionConf.js',
'node built/cli.js spec/directConnectConf.js',
'node built/cli.js spec/restartBrowserBetweenTestsConf.js',
// 'node built/cli.js spec/driverProviderLocalConf.js',
// 'node built/cli.js spec/driverProviderLocalConf.js --useBlockingProxy',
'node built/cli.js spec/driverProviderLocalConf.js',
'node built/cli.js spec/driverProviderLocalConf.js --useBlockingProxy',
'node built/cli.js spec/getCapabilitiesConf.js',
'node built/cli.js spec/controlLockConf.js',
'node built/cli.js spec/customFramework.js',
Expand Down
6 changes: 0 additions & 6 deletions spec/basic/lib_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ describe('protractor library', () => {
expect(await browser.driver.getCurrentUrl()).toMatch('#/form');
});

it('should unwrap WebElements', async() => {
await browser.get('index.html');
const ptorEl = element(by.binding('greet'));
await browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
});

it('should have access to the processed config block', async() => {
let containsMatching = (arr, string) => {
let contains = false;
Expand Down

0 comments on commit 39e02d1

Please sign in to comment.