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

Commit 881759e

Browse files
committed
feat(timeouts): add a unique error message when waitForAngular times out
To improve the readability of error messages, when waitForAngular times out it now produces a custom message. This should help clarify confusion for pages that continually poll using $interval. This change also adds more documentation on timeouts. See issue #109.
1 parent 37e0f1a commit 881759e

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

debugging/timeout_spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ describe('timeout possibilities', function() {
2929
expect(true).toEqual(true);
3030
});
3131

32+
describe('waitForAngular', function() {
33+
it('should timeout and give a reasonable message', function() {
34+
35+
ptor.driver.manage().timeouts().setScriptTimeout(55);
36+
37+
ptor.get('app/index.html#/async');
38+
39+
40+
var status =
41+
ptor.findElement(protractor.By.binding('slowHttpStatus'));
42+
var button = ptor.findElement(protractor.By.css('[ng-click="slowHttp()"]'));
43+
44+
expect(status.getText()).toEqual('not started');
45+
46+
button.click();
47+
48+
expect(status.getText()).toEqual('done');
49+
}, 5000); // The 5000 here sets the Jasmine spec timeout.
50+
});
51+
3252
it('should timeout due to Jasmine spec timeout', function() {
3353
ptor.driver.sleep(1000);
3454
expect(true).toBe(true);

docs/debugging.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ Jasmine tests have a timeout which can be set
104104
`it('should pass', function() {...}, 5555);`
105105

106106
Webdriver has a timeout for script execution, which can be set with
107-
`driver.manage().timeouts().setScriptTimeout`. Protractor sets this to 100
108-
seconds by default, so usually Jasmine will time out first.
107+
`driver.manage().timeouts().setScriptTimeout`. Protractor sets this to 5
108+
seconds by default.
109+
110+
Protractor attempts to synchronize with your page before performing actions.
111+
This means waiting for all $timeout or $http requests to resolve, as well as
112+
letting the current $digest cycle finish. If your page has not synchronized
113+
within the script execution timeout, Protractor will fail with the message
114+
'Timed out waiting for Protractor to synchronize with the page'.
109115

110116
If your website uses $timeout or $http to continuously poll, Protractor will
111117
interpret that as your site being busy and will time out on all requests. See

lib/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var startJasmineTests = function() {
146146
withCapabilities(config.capabilities).build();
147147

148148
driver.getSession().then(function(session) {
149-
driver.manage().timeouts().setScriptTimeout(100000);
149+
driver.manage().timeouts().setScriptTimeout(5000);
150150

151151
id = session.getId();
152152

lib/protractor.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ Protractor.prototype.waitForAngular = function() {
108108
return webdriver.promise.fulfilled();
109109
}
110110
return this.driver.executeAsyncScript(
111-
clientSideScripts.waitForAngular, this.rootEl);
111+
clientSideScripts.waitForAngular, this.rootEl).then(null, function(err) {
112+
console.log('Error was: ' + util.inspect(err));
113+
if (!/asynchronous script timeout/.test(err.message)) {
114+
throw err;
115+
}
116+
var timeout = /[\d\.]*\ seconds/.exec(err.message);
117+
throw 'Timed out waiting for Protractor to synchronize with ' +
118+
'the page after ' + timeout;
119+
});
112120
};
113121

114122
// TODO: activeelement also returns a WebElement.

referenceConf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ exports.config = {
8282
// If true, include stack traces in failures.
8383
includeStackTrace: true,
8484
// Default time to wait in ms before a test fails.
85-
defaultTimeoutInterval: 5000
85+
defaultTimeoutInterval: 30000
8686
}
8787
};

0 commit comments

Comments
 (0)