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

Commit

Permalink
Update with feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
heathkit committed Dec 15, 2016
1 parent 6a84646 commit 7f109ea
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 50 deletions.
4 changes: 2 additions & 2 deletions lib/bpRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -59,4 +59,4 @@ export class BlockingProxyRunner {
throw new Error('BlockingProxy not yet supported with directConnect!');
}
}
}
}
21 changes: 20 additions & 1 deletion lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------

Expand Down
6 changes: 3 additions & 3 deletions lib/driverProviders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<webdriver.WebDriver>} Array of existing webdriver instances.
Expand Down Expand Up @@ -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.

Expand Down
3 changes: 1 addition & 2 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>
protected abstract setupDriverEnv(): q.Promise<any>;

/**
* Teardown and destroy the environment and do any associated cleanup.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 26 additions & 2 deletions spec/basic/polling_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
34 changes: 0 additions & 34 deletions spec/blockingProxyConf.js

This file was deleted.

2 changes: 1 addition & 1 deletion spec/install/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
Expand Down

0 comments on commit 7f109ea

Please sign in to comment.