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

Commit

Permalink
feat(timeouts): add a unique error message when waitForAngular times out
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
juliemr committed Sep 25, 2013
1 parent 37e0f1a commit 881759e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
20 changes: 20 additions & 0 deletions debugging/timeout_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ describe('timeout possibilities', function() {
expect(true).toEqual(true);
});

describe('waitForAngular', function() {
it('should timeout and give a reasonable message', function() {

ptor.driver.manage().timeouts().setScriptTimeout(55);

ptor.get('app/index.html#/async');


var status =
ptor.findElement(protractor.By.binding('slowHttpStatus'));
var button = ptor.findElement(protractor.By.css('[ng-click="slowHttp()"]'));

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

button.click();

expect(status.getText()).toEqual('done');
}, 5000); // The 5000 here sets the Jasmine spec timeout.
});

it('should timeout due to Jasmine spec timeout', function() {
ptor.driver.sleep(1000);
expect(true).toBe(true);
Expand Down
10 changes: 8 additions & 2 deletions docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ Jasmine tests have a timeout which can be set
`it('should pass', function() {...}, 5555);`

Webdriver has a timeout for script execution, which can be set with
`driver.manage().timeouts().setScriptTimeout`. Protractor sets this to 100
seconds by default, so usually Jasmine will time out first.
`driver.manage().timeouts().setScriptTimeout`. Protractor sets this to 5
seconds by default.

Protractor attempts to synchronize with your page before performing actions.
This means waiting for all $timeout or $http requests to resolve, as well as
letting the current $digest cycle finish. If your page has not synchronized
within the script execution timeout, Protractor will fail with the message
'Timed out waiting for Protractor to synchronize with the page'.

If your website uses $timeout or $http to continuously poll, Protractor will
interpret that as your site being busy and will time out on all requests. See
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var startJasmineTests = function() {
withCapabilities(config.capabilities).build();

driver.getSession().then(function(session) {
driver.manage().timeouts().setScriptTimeout(100000);
driver.manage().timeouts().setScriptTimeout(5000);

id = session.getId();

Expand Down
10 changes: 9 additions & 1 deletion lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ Protractor.prototype.waitForAngular = function() {
return webdriver.promise.fulfilled();
}
return this.driver.executeAsyncScript(
clientSideScripts.waitForAngular, this.rootEl);
clientSideScripts.waitForAngular, this.rootEl).then(null, function(err) {
console.log('Error was: ' + util.inspect(err));
if (!/asynchronous script timeout/.test(err.message)) {
throw err;
}
var timeout = /[\d\.]*\ seconds/.exec(err.message);
throw 'Timed out waiting for Protractor to synchronize with ' +
'the page after ' + timeout;
});
};

// TODO: activeelement also returns a WebElement.
Expand Down
2 changes: 1 addition & 1 deletion referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ exports.config = {
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 5000
defaultTimeoutInterval: 30000
}
};

0 comments on commit 881759e

Please sign in to comment.