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

Commit 2007f06

Browse files
committedOct 30, 2015
feat(protractor): add flag to stop protractor from tracking $timeout
1 parent d7bb003 commit 2007f06

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed
 

Diff for: ‎docs/faq.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,20 @@ You may need to insert a `browser.wait` condition to make sure the load
193193
is complete before continuing.
194194

195195
How do I switch off an option in the CLI?
196-
------------------------------------------------------------------------------
196+
-----------------------------------------
197197
i.e. `webdriver-manager update --chrome=false` does not work.
198198
This has to do with the way `optimist` parses command line args. In order to pass a false value, do one of the following:
199199

200200
1) `webdriver-manager update --chrome=0`
201201

202202
2) `webdriver-manager update --no-chrome` (see https://github.com/substack/node-optimist#negate-fields)
203203

204+
Why does Protractor fail when I decorate $timeout?
205+
--------------------------------------------------
206+
Protractor tracks outstanding $timeouts by default, and reports them in the error message if Protractor fails to synchronize with Angular in time.
207+
208+
However, in order to do this Protractor needs to decorate $timeout. This means if your app decorates $timeout, you must turn off this behavior for Protractor. To do so pass in the 'untrackOutstandingTimeouts' flag.
209+
204210
I still have a question
205211
-----------------------
206212

Diff for: ‎docs/referenceConf.js

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ exports.config = {
250250
// CAUTION: This will cause your tests to slow down drastically.
251251
restartBrowserBetweenTests: false,
252252

253+
// Protractor will track outstanding $timeouts by default, and report them in
254+
// the error message if Protractor fails to synchronize with Angular in time.
255+
// In order to do this Protractor needs to decorate $timeout.
256+
// CAUTION: If your app decorates $timeout, you must turn on this flag. This
257+
// is false by default.
258+
untrackOutstandingTimeouts: false,
259+
253260
// ---------------------------------------------------------------------------
254261
// ----- The test framework --------------------------------------------------
255262
// ---------------------------------------------------------------------------

Diff for: ‎lib/protractor.js

+33-12
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ var buildElementHelper = function(ptor) {
9393
* @param {string=} opt_baseUrl A base URL to run get requests against.
9494
* @param {string=} opt_rootElement Selector element that has an ng-app in
9595
* scope.
96+
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
97+
* stop tracking outstanding $timeouts.
9698
*/
97-
var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
99+
var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement,
100+
opt_untrackOutstandingTimeouts) {
98101
// These functions should delegate to the webdriver instance, but should
99102
// wait for Angular to sync up before performing the action. This does not
100103
// include functions which are overridden by protractor below.
@@ -216,6 +219,13 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
216219
}
217220
});
218221

222+
/**
223+
* If true, Protractor will track outstanding $timeouts and report them in the
224+
* error message if Protractor fails to synchronize with Angular in time.
225+
* @private {boolean}
226+
*/
227+
this.trackOutstandingTimeouts_ = !opt_untrackOutstandingTimeouts;
228+
219229
/**
220230
* Information about mock modules that will be installed during every
221231
* get().
@@ -382,10 +392,15 @@ Protractor.prototype.waitForAngular = function(opt_description) {
382392
var errMsg = 'Timed out waiting for Protractor to synchronize with ' +
383393
'the page after ' + timeout + '. Please see ' +
384394
'https://github.com/angular/protractor/blob/master/docs/faq.md';
385-
var pendingTimeoutsPromise = self.executeScript_(
386-
'return window.NG_PENDING_TIMEOUTS',
387-
'Protractor.waitForAngular() - getting pending timeouts' + description
388-
);
395+
var pendingTimeoutsPromise;
396+
if (self.trackOutstandingTimeouts_) {
397+
pendingTimeoutsPromise = self.executeScript_(
398+
'return window.NG_PENDING_TIMEOUTS',
399+
'Protractor.waitForAngular() - getting pending timeouts' + description
400+
);
401+
} else {
402+
pendingTimeoutsPromise = webdriver.promise.fulfilled({});
403+
}
389404
var pendingHttpsPromise = self.executeScript_(
390405
clientSideScripts.getPendingHttpRequests,
391406
'Protractor.waitForAngular() - getting pending https' + description,
@@ -518,14 +533,15 @@ Protractor.prototype.getRegisteredMockModules = function() {
518533
* @private
519534
*/
520535
Protractor.prototype.addBaseMockModules_ = function() {
521-
this.addMockModule('protractorBaseModule_', function() {
522-
angular.module('protractorBaseModule_', []).
536+
this.addMockModule('protractorBaseModule_', function(trackOutstandingTimeouts) {
537+
var ngMod = angular.module('protractorBaseModule_', []).
523538
config(['$compileProvider', function($compileProvider) {
524539
if ($compileProvider.debugInfoEnabled) {
525540
$compileProvider.debugInfoEnabled(true);
526541
}
527-
}]).
528-
config(['$provide', function($provide) {
542+
}]);
543+
if (trackOutstandingTimeouts) {
544+
ngMod.config(['$provide', function($provide) {
529545
$provide.decorator('$timeout', ['$delegate', function($delegate) {
530546
var $timeout = $delegate;
531547

@@ -567,7 +583,8 @@ Protractor.prototype.addBaseMockModules_ = function() {
567583
return extendedTimeout;
568584
}]);
569585
}]);
570-
});
586+
}
587+
}, this.trackOutstandingTimeouts_);
571588
};
572589

573590
/**
@@ -1041,8 +1058,12 @@ Protractor.prototype.pause = function(opt_debugPort) {
10411058
*
10421059
* @param {webdriver.WebDriver} webdriver The configured webdriver instance.
10431060
* @param {string=} opt_baseUrl A URL to prepend to relative gets.
1061+
* @param {boolean=} opt_untrackOutstandingTimeouts Whether Protractor should
1062+
* stop tracking outstanding $timeouts.
10441063
* @return {Protractor}
10451064
*/
1046-
exports.wrapDriver = function(webdriver, opt_baseUrl, opt_rootElement) {
1047-
return new Protractor(webdriver, opt_baseUrl, opt_rootElement);
1065+
exports.wrapDriver = function(webdriver, opt_baseUrl, opt_rootElement,
1066+
opt_untrackOutstandingTimeouts) {
1067+
return new Protractor(webdriver, opt_baseUrl, opt_rootElement,
1068+
opt_untrackOutstandingTimeouts);
10481069
};

Diff for: ‎lib/runner.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Runner.prototype.createBrowser = function(plugins) {
182182
var driver = this.driverprovider_.getNewDriver();
183183

184184
var browser_ = protractor.wrapDriver(driver,
185-
config.baseUrl, config.rootElement);
185+
config.baseUrl, config.rootElement, config.untrackOutstandingTimeouts);
186186

187187
browser_.params = config.params;
188188
if (plugins) {
@@ -202,7 +202,6 @@ Runner.prototype.createBrowser = function(plugins) {
202202
}
203203
var self = this;
204204

205-
206205
browser_.ready =
207206
driver.manage().timeouts().setScriptTimeout(config.allScriptsTimeout);
208207

Diff for: ‎scripts/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ executor.addCommandlineTest('node lib/cli.js spec/errorTest/slowHttpAndTimeoutCo
130130
'*}'}
131131
]);
132132

133+
executor.addCommandlineTest('node lib/cli.js spec/errorTest/slowHttpAndTimeoutConf.js ' +
134+
'--untrackOutstandingTimeouts true')
135+
.expectExitCode(1)
136+
.expectErrors([
137+
{message: 'The following tasks were pending[\\s\\S]*\\$http: \/slowcall'},
138+
{message: '^((?!The following tasks were pending).)*$'}
139+
]);
140+
133141
// Check ngHint plugin
134142

135143
executor.addCommandlineTest(

0 commit comments

Comments
 (0)
This repository has been archived.