From 052b5919b4dc3a0256202ffa8eecba4715980409 Mon Sep 17 00:00:00 2001 From: Craig Nishina Date: Tue, 13 Nov 2018 16:21:44 -0800 Subject: [PATCH] fix - remove control flow from waitForAngularEnabled, waitForAngular, and angularAppRoot - Enabled the driverProviderLocal tests - Remove auto unwrap test for a WebElement. Reference PR #3471 --- lib/browser.ts | 106 ++++++++++---------------- lib/driverProviders/driverProvider.ts | 2 +- package.json | 1 + scripts/test.js | 4 +- spec/basic/lib_spec.js | 6 -- 5 files changed, 43 insertions(+), 76 deletions(-) diff --git a/lib/browser.ts b/lib/browser.ts index 6e98c21a3..610a29721 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -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} value The new selector. + * @param {string|webdriver.promise.Promise} valuePromise The new selector. * @returns A promise that resolves with the value of the selector. */ - angularAppRoot(value: string|wdpromise.Promise = null): wdpromise.Promise { - 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 = null): Promise { + 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; } /** @@ -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 = null): - wdpromise.Promise { - 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 = null): + Promise { + 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; } /** @@ -602,15 +590,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * @template T */ private executeAsyncScript_(script: string|Function, description: string, ...scriptArgs: any[]): - wdpromise.Promise { + Promise { 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; } /** @@ -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 { + async waitForAngular(opt_description?: string): Promise { 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 = () => { + let runWaitForAngularScript = async(): Promise => { 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); } }; @@ -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; @@ -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); } diff --git a/lib/driverProviders/driverProvider.ts b/lib/driverProviders/driverProvider.ts index a35b1e981..10831138f 100644 --- a/lib/driverProviders/driverProvider.ts +++ b/lib/driverProviders/driverProvider.ts @@ -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 (_) { diff --git a/package.json b/package.json index f70249601..1bcea3357 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/scripts/test.js b/scripts/test.js index 5d7dd0b87..8fa8c7c65 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -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', diff --git a/spec/basic/lib_spec.js b/spec/basic/lib_spec.js index a55a41978..30cc63600 100644 --- a/spec/basic/lib_spec.js +++ b/spec/basic/lib_spec.js @@ -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;