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

Commit

Permalink
feat(config): allow setting the get page timeout globally from the co…
Browse files Browse the repository at this point in the history
…nfig

To change the timeout for how long a page is allowed to stall on `browser.get`, change
`getPageTimeout: timeout_in_millis` in the configuration. As before, you may also
change the timeout for one particular `get` call by using a second parameter:
`browser.get(url, timeout_in_sec)`

Breaking Change:

This change contains a small breaking change for consistency. Previously,
the second parameter to `get` changed the timeout in seconds. Now, the units
are milliseconds. This is consistent with all the other timeouts, as well as
base JavaScript functions like setTimeout.

 - before: `browser.get(url, 4)`
 - after: `browser.get(url, 4000)`
  • Loading branch information
juliemr committed Jul 17, 2014
1 parent d2634e5 commit 51a5e89
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 6 additions & 2 deletions docs/referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ exports.config = {
// body, but is necessary if ng-app is on a descendant of <body>.
rootElement: 'body',

// The timeout for each script run on the browser. This should be longer
// than the maximum time your application needs to stabilize between tasks.
// The timeout in milliseconds for each script run on the browser. This should
// be longer than the maximum time your application needs to stabilize between
// tasks.
allScriptsTimeout: 11000,

// How long to wait for a page to load.
getPageTimeout: 10000,

// A callback function called once protractor is ready and available, and
// before the specs are executed.
// If multiple capabilities are being run, this will run once per
Expand Down
4 changes: 2 additions & 2 deletions docs/timeouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ be loaded and the new URL to appear before continuing.

- Default timeout: 10 seconds

- How to change: Pass an additional parameter: `browser.get(address, timeout_in_sec)`
- How to change: To change globally, add `getPageTimeout: timeout_in_millis` to your Protractor configuration file. For an individual call to `get`, pass an additional parameter: `browser.get(address, timeout_in_millis)`

**Waiting for Page Synchronization**

Expand All @@ -39,7 +39,7 @@ Protractor only works with Angular applications, so it waits for the `angular` v

- Default timeout: 10 seconds

- How to change: Pass an additional parameter: `browser.get(address, timeout_in_sec)`
- How to change: To change globally, add `getPageTimeout: timeout_in_millis` to your Protractor configuration file. For an individual call to `get`, pass an additional parameter: `browser.get(address, timeout_in_millis)`


Timeouts from WebDriver
Expand Down
1 change: 1 addition & 0 deletions lib/configParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var ConfigParser = function() {
multiCapabilities: [],
rootElement: 'body',
allScriptsTimeout: 11000,
getPageTimeout: 10000,
params: {},
framework: 'jasmine',
jasmineNodeOpts: {
Expand Down
21 changes: 15 additions & 6 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var STACK_SUBSTRINGS_TO_FILTER = [
];

var DEFAULT_RESET_URL = 'data:text/html,<html></html>';
var DEFAULT_GET_PAGE_TIMEOUT = 10000;

/*
* Mix in other webdriver functionality to be accessible via protractor.
Expand Down Expand Up @@ -836,6 +837,13 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
*/
this.ignoreSynchronization = false;

/**
* Timeout in milliseconds to wait for pages to load when calling `get`.
*
* @type {number}
*/
this.getPageTimeout = DEFAULT_GET_PAGE_TIMEOUT;

/**
* An object that holds custom test parameters.
*
Expand Down Expand Up @@ -976,12 +984,12 @@ Protractor.prototype.removeMockModule = function(name) {
* the wrapped webdriver directly.
*
* @param {string} destination Destination URL.
* @param {number=} opt_timeout Number of seconds to wait for Angular to start.
* @param {number=} opt_timeout Number of milliseconds to wait for Angular to
* start.
*/
Protractor.prototype.get = function(destination, opt_timeout) {
var timeout = opt_timeout || 10;
var timeout = opt_timeout ? opt_timeout : this.getPageTimeout;
var self = this;
var timeoutMillis = timeout * 1000;

destination = url.resolve(this.baseUrl, destination);

Expand Down Expand Up @@ -1012,11 +1020,12 @@ Protractor.prototype.get = function(destination, opt_timeout) {
throw err;
}
});
}, timeoutMillis,
'Timed out waiting for page to load after ' + timeoutMillis + 'ms');
}, timeout,
'Timed out waiting for page to load after ' + timeout + 'ms');

// Make sure the page is an Angular page.
self.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
self.driver.executeAsyncScript(clientSideScripts.testForAngular,
Math.floor(timeout / 1000)).
then(function(angularTestResult) {
var hasAngular = angularTestResult[0];
if (!hasAngular) {
Expand Down
4 changes: 4 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ Runner.prototype.setupGlobals_ = function(driver) {
}
});

if (this.config_.getPageTimeout) {
browser.getPageTimeout = this.config_.getPageTimeout;
}

// Export protractor to the global namespace to be used in tests.
global.protractor = protractor;
global.browser = browser;
Expand Down

0 comments on commit 51a5e89

Please sign in to comment.