Skip to content

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 angular#3471
  • Loading branch information
cnishina committed Nov 14, 2018
1 parent 8796ad8 commit 052b591
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 76 deletions.
106 changes: 39 additions & 67 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 All @@ -656,20 +638,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
}
})
.then(
() => {
return this.driver.controlFlow()
.execute(
() => {
return this.plugins_.waitForPromise(this);
},
'Plugins.waitForPromise()')
.then(() => {
return this.driver.wait(() => {
return this.plugins_.waitForCondition(this).then((results: boolean[]) => {
return results.reduce((x, y) => x && y, true);
});
}, this.allScriptsTimeout, 'Plugins.waitForCondition()');
});
async () => {
await this.plugins_.waitForPromise(this);
return this.driver.wait(async () => {
let results = await this.plugins_.waitForCondition(this);
return results.reduce((x, y) => x && y, true);
}, this.allScriptsTimeout, 'Plugins.waitForCondition()');
},
(err: Error) => {
let timeout: RegExpExecArray;
Expand Down Expand Up @@ -978,16 +952,14 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
.then(() => {
// Reset bpClient sync
if (this.bpClient) {
return this.driver.controlFlow().execute(() => {
return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
});
return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
}
})
.then(() => {
// Run Plugins
return this.driver.controlFlow().execute(() => {
if (!this.ignoreSynchronization) {
return this.plugins_.onPageStable(this);
});
}
})
.then(() => null);
}
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 052b591

Please sign in to comment.