From 7f109ea1e407369ac33acede54a26fd2e81e9324 Mon Sep 17 00:00:00 2001 From: Michael Giambalvo Date: Wed, 14 Dec 2016 11:35:04 -0800 Subject: [PATCH] Update with feedback. --- lib/bpRunner.ts | 4 ++-- lib/browser.ts | 21 ++++++++++++++++- lib/config.ts | 6 ++--- lib/driverProviders/README.md | 6 ++--- lib/driverProviders/driverProvider.ts | 3 +-- package.json | 2 +- scripts/test.js | 1 + spec/basic/elements_spec.js | 2 +- spec/basic/polling_spec.js | 28 ++++++++++++++++++++-- spec/blockingProxyConf.js | 34 --------------------------- spec/install/tsconfig.json | 2 +- 11 files changed, 59 insertions(+), 50 deletions(-) delete mode 100644 spec/blockingProxyConf.js diff --git a/lib/bpRunner.ts b/lib/bpRunner.ts index bd73e4c51..80f9c2cca 100644 --- a/lib/bpRunner.ts +++ b/lib/bpRunner.ts @@ -4,7 +4,7 @@ import * as q from 'q'; import {Config} from './config'; import {Logger} from './logger'; -const BP_PATH = 'node_modules/blocking-proxy/built/lib/bin.js'; +const BP_PATH = require.resolve('blocking-proxy/built/lib/bin.js'); let logger = new Logger('BlockingProxy'); @@ -59,4 +59,4 @@ export class BlockingProxyRunner { throw new Error('BlockingProxy not yet supported with directConnect!'); } } -} \ No newline at end of file +} diff --git a/lib/browser.ts b/lib/browser.ts index 4e17cb682..aa055d6b8 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -193,12 +193,15 @@ export class ProtractorBrowser extends Webdriver { * tests to become flaky. This should be used only when necessary, such as * when a page continuously polls an API using $timeout. * + * This property is deprecated - please use waitForAngularEnabled instead. + * + * @deprecated * @type {boolean} */ set ignoreSynchronization(value) { this.driver.controlFlow().execute(() => { if (this.bpClient) { - logger.info('Setting synchronization ' + value); + logger.debug('Setting waitForAngular' + value); this.bpClient.setSynchronization(!value); } }, `Set proxy synchronization to ${value}`); @@ -350,6 +353,22 @@ export class ProtractorBrowser extends Webdriver { this.ExpectedConditions = new ProtractorExpectedConditions(this); } + /** + * If set to false, Protractor will not wait for Angular $http and $timeout + * tasks to complete before interacting with the browser. This can cause + * flaky tests, but should be used if, for instance, your app continuously + * polls an API with $timeout. + * + * Call waitForAngularEnabled() without passing a value to read the current + * state without changing it. + */ + waitForAngularEnabled(enabled: boolean = null): boolean { + if (enabled != null) { + this.ignoreSynchronization = !enabled; + } + return !this.ignoreSynchronization; + } + /** * Get the processed configuration object that is currently being run. This * will contain the specs and capabilities properties of the current runner diff --git a/lib/config.ts b/lib/config.ts index c3864a3b3..59ba6a99d 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -97,10 +97,10 @@ export interface Config { /** * If specified, connect to webdriver through a proxy that manages client-side - * synchronization. This option is intended for testing an experimental feature - * and is not meant to be used by end users. + * synchronization. Blocking Proxy is an experimental feature and may change + * without notice. */ - useBlockingProxy?: string; + useBlockingProxy?: boolean; // ---- 3. To use remote browsers via Sauce Labs ----------------------------- diff --git a/lib/driverProviders/README.md b/lib/driverProviders/README.md index aa098b702..2cc0919a1 100644 --- a/lib/driverProviders/README.md +++ b/lib/driverProviders/README.md @@ -11,7 +11,7 @@ Each file exports a function which takes in the configuration as a parameter and * @return {q.promise} A promise which will resolve when the environment is * ready to test. */ -DriverProvider.prototype.setupEnv +DriverProvider.prototype.setupDriverEnv /** * @return {Array.} Array of existing webdriver instances. @@ -47,9 +47,9 @@ DriverProvider.prototype.updateJob Requirements ------------ - - `setupEnv` will be called before the test framework is loaded, so any + - `setupDriverEnv` will be called before the test framework is loaded, so any pre-work which might cause timeouts on the first test should be done there. - `getNewDriver` will be called once right after `setupEnv` to generate the + `getNewDriver` will be called once right after `setupDriverEnv` to generate the initial driver, and possibly during the middle of the test if users request additional browsers. diff --git a/lib/driverProviders/driverProvider.ts b/lib/driverProviders/driverProvider.ts index 187c705e5..27562cd3e 100644 --- a/lib/driverProviders/driverProvider.ts +++ b/lib/driverProviders/driverProvider.ts @@ -118,8 +118,7 @@ export abstract class DriverProvider { * Set up environment specific to a particular driver provider. Overridden * by each driver provider. */ - protected abstract setupDriverEnv(): - q.Promise + protected abstract setupDriverEnv(): q.Promise; /** * Teardown and destroy the environment and do any associated cleanup. diff --git a/package.json b/package.json index 2cbf97ecc..a048a79ab 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@types/q": "^0.0.32", "@types/selenium-webdriver": "~2.53.31", "adm-zip": "0.4.7", - "blocking-proxy": "^0.0.1", + "blocking-proxy": "0.0.2", "chalk": "^1.1.3", "glob": "^7.0.3", "jasmine": "2.4.1", diff --git a/scripts/test.js b/scripts/test.js index df777a447..7d7439a3f 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -4,6 +4,7 @@ var Executor = require('./test/test_util').Executor; var passingTests = [ 'node built/cli.js spec/basicConf.js', + 'node built/cli.js spec/basicConf.js --useBlockingProxy', 'node built/cli.js spec/multiConf.js', 'node built/cli.js spec/altRootConf.js', 'node built/cli.js spec/onCleanUpAsyncReturnValueConf.js', diff --git a/spec/basic/elements_spec.js b/spec/basic/elements_spec.js index 74370031f..624aa9e08 100644 --- a/spec/basic/elements_spec.js +++ b/spec/basic/elements_spec.js @@ -465,7 +465,7 @@ describe('ElementArrayFinder', function() { ]); }); - fit('should map and resolve multiple promises', function() { + it('should map and resolve multiple promises', function() { browser.get('index.html#/form'); var labels = element.all(by.css('#animals ul li')).map(function(elm) { return { diff --git a/spec/basic/polling_spec.js b/spec/basic/polling_spec.js index 376158229..80e05e253 100644 --- a/spec/basic/polling_spec.js +++ b/spec/basic/polling_spec.js @@ -30,8 +30,32 @@ describe('synchronizing with pages that poll', function() { }); }); + it('avoids timeouts using waitForAngularEnabled', function() { + var startButton = element(by.id('pollstarter')); + + var count = element(by.binding('count')); + expect(count.getText()).toEqual('0'); + + startButton.click(); + + // Turn this off to see timeouts. + browser.waitForAngularEnabled(false); + + expect(browser.waitForAngularEnabled()).toBeFalsy(); + + count.getText().then(function(text) { + expect(text).toBeGreaterThan(-1); + }); + + browser.sleep(2000); + + count.getText().then(function(text) { + expect(text).toBeGreaterThan(1); + }); + }); + afterEach(function() { - // Remember to turn it off when you're done! - browser.ignoreSynchronization = false; + // Remember to turn it back on when you're done! + browser.waitForAngularEnabled(true); }); }); diff --git a/spec/blockingProxyConf.js b/spec/blockingProxyConf.js deleted file mode 100644 index c5c182c9f..000000000 --- a/spec/blockingProxyConf.js +++ /dev/null @@ -1,34 +0,0 @@ -var env = require('./environment.js'); - -// The main suite of Protractor tests. -exports.config = { - seleniumAddress: env.seleniumAddress, - - framework: 'jasmine', - - // Spec patterns are relative to this directory. - specs: [ - 'basic/synchronize_spec.js', - 'ng2/async_spec.js', - 'ng2/timeout_spec.js', - 'hybrid/async_spec.js' - ], - - blockingProxyUrl: 'http://localhost:8111', - - // Exclude patterns are relative to this directory. - exclude: [ - 'basic/exclude*.js' - ], - - capabilities: env.capabilities, - - baseUrl: env.baseUrl + '/ng1/', - - params: { - login: { - user: 'Jane', - password: '1234' - } - } -}; diff --git a/spec/install/tsconfig.json b/spec/install/tsconfig.json index 366a1d730..c752f8b29 100644 --- a/spec/install/tsconfig.json +++ b/spec/install/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es6", "module": "commonjs", "moduleResolution": "node", "sourceMap": false,