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

Commit e13478b

Browse files
committed
fix - remove control flow from waitForAngularEnabled, waitForAngular, and angularAppRoot
- Enabled the driverProviderLocal tests - Remove auto unwrap test for a WebElement. Reference PR #3471
1 parent 8796ad8 commit e13478b

File tree

5 files changed

+43
-76
lines changed

5 files changed

+43
-76
lines changed

lib/browser.ts

+39-67
Original file line numberDiff line numberDiff line change
@@ -193,24 +193,18 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
193193
* this method is called use the new app root. Pass nothing to get a promise that
194194
* resolves to the value of the selector.
195195
*
196-
* @param {string|webdriver.promise.Promise<string>} value The new selector.
196+
* @param {string|webdriver.promise.Promise<string>} valuePromise The new selector.
197197
* @returns A promise that resolves with the value of the selector.
198198
*/
199-
angularAppRoot(value: string|wdpromise.Promise<string> = null): wdpromise.Promise<string> {
200-
return this.driver.controlFlow().execute(() => {
201-
if (value != null) {
202-
return wdpromise.when(value).then((value: string) => {
203-
this.internalRootEl = value;
204-
if (this.bpClient) {
205-
const bpCommandPromise = this.bpClient.setWaitParams(value);
206-
// Convert to webdriver promise as best as possible
207-
return wdpromise.when(bpCommandPromise as any).then(() => this.internalRootEl);
208-
}
209-
return this.internalRootEl;
210-
});
199+
async angularAppRoot(valuePromise: string|wdpromise.Promise<string> = null): Promise<string> {
200+
if (valuePromise != null) {
201+
const value = await Promise.resolve(valuePromise);
202+
this.internalRootEl = value;
203+
if (this.bpClient) {
204+
await this.bpClient.setWaitParams(value);
211205
}
212-
return wdpromise.when(this.internalRootEl);
213-
}, `Set angular root selector to ${value}`);
206+
}
207+
return this.internalRootEl;
214208
}
215209

216210
/**
@@ -417,23 +411,17 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
417411
* Call waitForAngularEnabled() without passing a value to read the current
418412
* state without changing it.
419413
*/
420-
waitForAngularEnabled(enabled: boolean|wdpromise.Promise<boolean> = null):
421-
wdpromise.Promise<boolean> {
422-
if (enabled != null) {
423-
const ret = this.driver.controlFlow().execute(() => {
424-
return wdpromise.when(enabled).then((enabled: boolean) => {
425-
if (this.bpClient) {
426-
logger.debug('Setting waitForAngular' + !enabled);
427-
const bpCommandPromise = this.bpClient.setWaitEnabled(enabled);
428-
// Convert to webdriver promise as best as possible
429-
return wdpromise.when(bpCommandPromise as any).then(() => enabled);
430-
}
431-
});
432-
}, `Set proxy synchronization enabled to ${enabled}`);
414+
async waitForAngularEnabled(enabledPromise: boolean|wdpromise.Promise<boolean> = null):
415+
Promise<boolean> {
416+
if (enabledPromise != null) {
417+
const enabled = await Promise.resolve(enabledPromise);
418+
if (this.bpClient) {
419+
logger.debug('Setting waitForAngular' + !enabled);
420+
await this.bpClient.setWaitEnabled(enabled);
421+
}
433422
this.internalIgnoreSynchronization = !enabled;
434-
return ret;
435423
}
436-
return wdpromise.when(!this.ignoreSynchronization);
424+
return !this.ignoreSynchronization;
437425
}
438426

439427
/**
@@ -602,15 +590,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
602590
* @template T
603591
*/
604592
private executeAsyncScript_(script: string|Function, description: string, ...scriptArgs: any[]):
605-
wdpromise.Promise<any> {
593+
Promise<any> {
606594
if (typeof script === 'function') {
607595
script = 'return (' + script + ').apply(null, arguments);';
608596
}
609597
return this.driver.schedule(
610-
new Command(CommandName.EXECUTE_ASYNC_SCRIPT)
611-
.setParameter('script', script)
612-
.setParameter('args', scriptArgs),
613-
description);
598+
new Command(CommandName.EXECUTE_ASYNC_SCRIPT)
599+
.setParameter('script', script)
600+
.setParameter('args', scriptArgs),
601+
description) as Promise<any>;
614602
}
615603

616604
/**
@@ -624,26 +612,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
624612
* @returns {!webdriver.promise.Promise} A promise that will resolve to the
625613
* scripts return value.
626614
*/
627-
waitForAngular(opt_description?: string): wdpromise.Promise<any> {
615+
async waitForAngular(opt_description?: string): Promise<any> {
628616
let description = opt_description ? ' - ' + opt_description : '';
629617
if (this.ignoreSynchronization) {
630-
return this.driver.controlFlow().execute(() => {
631-
return true;
632-
}, 'Ignore Synchronization Protractor.waitForAngular()');
618+
return Promise.resolve(true);
633619
}
634620

635-
let runWaitForAngularScript: () => wdpromise.Promise<any> = () => {
621+
let runWaitForAngularScript = async(): Promise<any> => {
636622
if (this.plugins_.skipAngularStability() || this.bpClient) {
637-
return this.driver.controlFlow().execute(() => {
638-
return wdpromise.when(null);
639-
}, 'bpClient or plugin stability override');
623+
return Promise.resolve(null);
640624
} else {
641625
// Need to wrap this so that we read rootEl in the control flow, not synchronously.
642-
return this.angularAppRoot().then((rootEl: string) => {
643-
return this.executeAsyncScript_(
644-
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description,
645-
rootEl);
646-
});
626+
let rootEl = await this.angularAppRoot();
627+
return this.executeAsyncScript_(
628+
clientSideScripts.waitForAngular, 'Protractor.waitForAngular()' + description, rootEl);
647629
}
648630
};
649631

@@ -656,20 +638,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
656638
}
657639
})
658640
.then(
659-
() => {
660-
return this.driver.controlFlow()
661-
.execute(
662-
() => {
663-
return this.plugins_.waitForPromise(this);
664-
},
665-
'Plugins.waitForPromise()')
666-
.then(() => {
667-
return this.driver.wait(() => {
668-
return this.plugins_.waitForCondition(this).then((results: boolean[]) => {
669-
return results.reduce((x, y) => x && y, true);
670-
});
671-
}, this.allScriptsTimeout, 'Plugins.waitForCondition()');
672-
});
641+
async() => {
642+
await this.plugins_.waitForPromise(this);
643+
return this.driver.wait(async() => {
644+
let results = await this.plugins_.waitForCondition(this);
645+
return results.reduce((x, y) => x && y, true);
646+
}, this.allScriptsTimeout, 'Plugins.waitForCondition()');
673647
},
674648
(err: Error) => {
675649
let timeout: RegExpExecArray;
@@ -978,16 +952,14 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
978952
.then(() => {
979953
// Reset bpClient sync
980954
if (this.bpClient) {
981-
return this.driver.controlFlow().execute(() => {
982-
return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
983-
});
955+
return this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
984956
}
985957
})
986958
.then(() => {
987959
// Run Plugins
988-
return this.driver.controlFlow().execute(() => {
960+
if (!this.ignoreSynchronization) {
989961
return this.plugins_.onPageStable(this);
990-
});
962+
}
991963
})
992964
.then(() => null);
993965
}

lib/driverProviders/driverProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export abstract class DriverProvider {
7777
if (driver.getSession() !== undefined) {
7878
const session = await driver.getSession();
7979
if (session) {
80-
return driver.quit();
80+
return await driver.quit();
8181
}
8282
}
8383
} catch (_) {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"pretest": "gulp pretest",
7777
"start": "cd testapp && npm start",
7878
"test": "node scripts/test.js",
79+
"tsc": "tsc",
7980
"website": "cd website && npm start",
8081
"compile_to_es5": "gulp compile_to_es5"
8182
},

scripts/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ var passingTests = [
3131
'node built/cli.js spec/interactionConf.js',
3232
'node built/cli.js spec/directConnectConf.js',
3333
'node built/cli.js spec/restartBrowserBetweenTestsConf.js',
34-
// 'node built/cli.js spec/driverProviderLocalConf.js',
35-
// 'node built/cli.js spec/driverProviderLocalConf.js --useBlockingProxy',
34+
'node built/cli.js spec/driverProviderLocalConf.js',
35+
'node built/cli.js spec/driverProviderLocalConf.js --useBlockingProxy',
3636
'node built/cli.js spec/getCapabilitiesConf.js',
3737
'node built/cli.js spec/controlLockConf.js',
3838
'node built/cli.js spec/customFramework.js',

spec/basic/lib_spec.js

-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ describe('protractor library', () => {
4242
expect(await browser.driver.getCurrentUrl()).toMatch('#/form');
4343
});
4444

45-
it('should unwrap WebElements', async() => {
46-
await browser.get('index.html');
47-
const ptorEl = element(by.binding('greet'));
48-
await browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
49-
});
50-
5145
it('should have access to the processed config block', async() => {
5246
let containsMatching = (arr, string) => {
5347
let contains = false;

0 commit comments

Comments
 (0)