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

Commit cae175c

Browse files
committedMar 17, 2016
feat(plugins) Calculate skipAngularStability dynamically.
This allows plugins to turn Protractor's default synchronization on and off as needed.
1 parent 918865b commit cae175c

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed
 

‎lib/plugins.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var Plugins = function(config) {
2222
this.pluginObjs = [];
2323
this.assertions = {};
2424
this.resultsReported = false;
25-
this.skipAngularStability = false;
2625
this.pluginConfs.forEach(function(pluginConf, i) {
2726
var path;
2827
if (pluginConf.path) {
@@ -46,8 +45,6 @@ var Plugins = function(config) {
4645
}
4746

4847
annotatePluginObj(self, pluginObj, pluginConf, i);
49-
self.skipAngularStability = self.skipAngularStability ||
50-
pluginObj.skipAngularStability;
5148

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

154+
/**
155+
* Returns true if any loaded plugin has skipAngularStability enabled.
156+
*
157+
* @return {boolean}
158+
*/
159+
Plugins.prototype.skipAngularStability = function() {
160+
var result = this.pluginObjs.reduce(function(skip, pluginObj) {
161+
return pluginObj.skipAngularStability || skip;
162+
}, false);
163+
return result;
164+
};
165+
157166
/**
158167
* Calls a function from a plugin safely. If the plugin's function throws an
159168
* exception or returns a rejected promise, that failure will be logged as a

‎lib/protractor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Protractor.prototype.waitForAngular = function(opt_description) {
357357
}
358358

359359
function runWaitForAngularScript() {
360-
if (self.plugins_.skipAngularStability) {
360+
if (self.plugins_.skipAngularStability()) {
361361
return webdriver.promise.fulfilled();
362362
} else if (self.rootEl) {
363363
return self.executeAsyncScript_(

‎spec/plugins/skipStabilityConf.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var env = require('../environment.js'),
2+
q = require('q');
3+
4+
// Verifies that plugins can change skipAngularStability on the fly.
5+
exports.config = {
6+
seleniumAddress: env.seleniumAddress,
7+
8+
framework: 'jasmine',
9+
10+
// Spec patterns are relative to this directory.
11+
specs: [
12+
'specs/skip_stability_spec.js'
13+
],
14+
15+
capabilities: env.capabilities,
16+
17+
baseUrl: env.baseUrl + '/ng1/',
18+
19+
// Define a plugin that allows skipAngularStability to be changed.
20+
plugins: [{
21+
inline: {
22+
setup: function() {
23+
this.skipAngularStability = false;
24+
var plugin = this;
25+
26+
protractor._PluginSetSkipStability = function(newValue) {
27+
plugin.skipAngularStability = newValue;
28+
};
29+
}
30+
}
31+
}]
32+
};
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
describe('plugins that can disable synchronization', function() {
2+
beforeEach(function() {
3+
browser.get('index.html#/async');
4+
});
5+
6+
it('DOES NOT wait for $timeout with synchronization disabled', function() {
7+
protractor._PluginSetSkipStability(true);
8+
var status = element(by.binding('slowAngularTimeoutStatus'));
9+
var button = element(by.css('[ng-click="slowAngularTimeout()"]'));
10+
11+
expect(status.getText()).toEqual('not started');
12+
13+
button.click();
14+
15+
expect(status.getText()).toEqual('pending...');
16+
});
17+
18+
it('waits for $timeout with synchronization enabled', function() {
19+
protractor._PluginSetSkipStability(false);
20+
var status = element(by.binding('slowAngularTimeoutStatus'));
21+
var button = element(by.css('[ng-click="slowAngularTimeout()"]'));
22+
23+
expect(status.getText()).toEqual('not started');
24+
25+
button.click();
26+
27+
expect(status.getText()).toEqual('done');
28+
});
29+
});

0 commit comments

Comments
 (0)
This repository has been archived.