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

Commit

Permalink
feat(plugins) Calculate skipAngularStability dynamically.
Browse files Browse the repository at this point in the history
This allows plugins to turn Protractor's default synchronization on and
off as needed.
  • Loading branch information
heathkit committed Mar 17, 2016
1 parent 918865b commit cae175c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var Plugins = function(config) {
this.pluginObjs = [];
this.assertions = {};
this.resultsReported = false;
this.skipAngularStability = false;
this.pluginConfs.forEach(function(pluginConf, i) {
var path;
if (pluginConf.path) {
Expand All @@ -46,8 +45,6 @@ var Plugins = function(config) {
}

annotatePluginObj(self, pluginObj, pluginConf, i);
self.skipAngularStability = self.skipAngularStability ||
pluginObj.skipAngularStability;

log.debug('Plugin "' + pluginObj.name + '" loaded.');
self.pluginObjs.push(pluginObj);
Expand Down Expand Up @@ -154,6 +151,18 @@ Plugins.prototype.getResults = function() {
return results;
};

/**
* Returns true if any loaded plugin has skipAngularStability enabled.
*
* @return {boolean}
*/
Plugins.prototype.skipAngularStability = function() {
var result = this.pluginObjs.reduce(function(skip, pluginObj) {
return pluginObj.skipAngularStability || skip;
}, false);
return result;
};

/**
* Calls a function from a plugin safely. If the plugin's function throws an
* exception or returns a rejected promise, that failure will be logged as a
Expand Down
2 changes: 1 addition & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Protractor.prototype.waitForAngular = function(opt_description) {
}

function runWaitForAngularScript() {
if (self.plugins_.skipAngularStability) {
if (self.plugins_.skipAngularStability()) {
return webdriver.promise.fulfilled();
} else if (self.rootEl) {
return self.executeAsyncScript_(
Expand Down
32 changes: 32 additions & 0 deletions spec/plugins/skipStabilityConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var env = require('../environment.js'),
q = require('q');

// Verifies that plugins can change skipAngularStability on the fly.
exports.config = {
seleniumAddress: env.seleniumAddress,

framework: 'jasmine',

// Spec patterns are relative to this directory.
specs: [
'specs/skip_stability_spec.js'
],

capabilities: env.capabilities,

baseUrl: env.baseUrl + '/ng1/',

// Define a plugin that allows skipAngularStability to be changed.
plugins: [{
inline: {
setup: function() {
this.skipAngularStability = false;
var plugin = this;

protractor._PluginSetSkipStability = function(newValue) {
plugin.skipAngularStability = newValue;
};
}
}
}]
};
29 changes: 29 additions & 0 deletions spec/plugins/specs/skip_stability_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe('plugins that can disable synchronization', function() {
beforeEach(function() {
browser.get('index.html#/async');
});

it('DOES NOT wait for $timeout with synchronization disabled', function() {
protractor._PluginSetSkipStability(true);
var status = element(by.binding('slowAngularTimeoutStatus'));
var button = element(by.css('[ng-click="slowAngularTimeout()"]'));

expect(status.getText()).toEqual('not started');

button.click();

expect(status.getText()).toEqual('pending...');
});

it('waits for $timeout with synchronization enabled', function() {
protractor._PluginSetSkipStability(false);
var status = element(by.binding('slowAngularTimeoutStatus'));
var button = element(by.css('[ng-click="slowAngularTimeout()"]'));

expect(status.getText()).toEqual('not started');

button.click();

expect(status.getText()).toEqual('done');
});
});

0 comments on commit cae175c

Please sign in to comment.