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

Commit 51a5e89

Browse files
committed
feat(config): allow setting the get page timeout globally from the config
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)`
1 parent d2634e5 commit 51a5e89

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

Diff for: docs/referenceConf.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ exports.config = {
128128
// body, but is necessary if ng-app is on a descendant of <body>.
129129
rootElement: 'body',
130130

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

136+
// How long to wait for a page to load.
137+
getPageTimeout: 10000,
138+
135139
// A callback function called once protractor is ready and available, and
136140
// before the specs are executed.
137141
// If multiple capabilities are being run, this will run once per

Diff for: docs/timeouts.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ be loaded and the new URL to appear before continuing.
1717

1818
- Default timeout: 10 seconds
1919

20-
- How to change: Pass an additional parameter: `browser.get(address, timeout_in_sec)`
20+
- 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)`
2121

2222
**Waiting for Page Synchronization**
2323

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

4040
- Default timeout: 10 seconds
4141

42-
- How to change: Pass an additional parameter: `browser.get(address, timeout_in_sec)`
42+
- 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)`
4343

4444

4545
Timeouts from WebDriver

Diff for: lib/configParser.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var ConfigParser = function() {
2525
multiCapabilities: [],
2626
rootElement: 'body',
2727
allScriptsTimeout: 11000,
28+
getPageTimeout: 10000,
2829
params: {},
2930
framework: 'jasmine',
3031
jasmineNodeOpts: {

Diff for: lib/protractor.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var STACK_SUBSTRINGS_TO_FILTER = [
2424
];
2525

2626
var DEFAULT_RESET_URL = 'data:text/html,<html></html>';
27+
var DEFAULT_GET_PAGE_TIMEOUT = 10000;
2728

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

840+
/**
841+
* Timeout in milliseconds to wait for pages to load when calling `get`.
842+
*
843+
* @type {number}
844+
*/
845+
this.getPageTimeout = DEFAULT_GET_PAGE_TIMEOUT;
846+
839847
/**
840848
* An object that holds custom test parameters.
841849
*
@@ -976,12 +984,12 @@ Protractor.prototype.removeMockModule = function(name) {
976984
* the wrapped webdriver directly.
977985
*
978986
* @param {string} destination Destination URL.
979-
* @param {number=} opt_timeout Number of seconds to wait for Angular to start.
987+
* @param {number=} opt_timeout Number of milliseconds to wait for Angular to
988+
* start.
980989
*/
981990
Protractor.prototype.get = function(destination, opt_timeout) {
982-
var timeout = opt_timeout || 10;
991+
var timeout = opt_timeout ? opt_timeout : this.getPageTimeout;
983992
var self = this;
984-
var timeoutMillis = timeout * 1000;
985993

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

@@ -1012,11 +1020,12 @@ Protractor.prototype.get = function(destination, opt_timeout) {
10121020
throw err;
10131021
}
10141022
});
1015-
}, timeoutMillis,
1016-
'Timed out waiting for page to load after ' + timeoutMillis + 'ms');
1023+
}, timeout,
1024+
'Timed out waiting for page to load after ' + timeout + 'ms');
10171025

10181026
// Make sure the page is an Angular page.
1019-
self.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
1027+
self.driver.executeAsyncScript(clientSideScripts.testForAngular,
1028+
Math.floor(timeout / 1000)).
10201029
then(function(angularTestResult) {
10211030
var hasAngular = angularTestResult[0];
10221031
if (!hasAngular) {

Diff for: lib/runner.js

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ Runner.prototype.setupGlobals_ = function(driver) {
177177
}
178178
});
179179

180+
if (this.config_.getPageTimeout) {
181+
browser.getPageTimeout = this.config_.getPageTimeout;
182+
}
183+
180184
// Export protractor to the global namespace to be used in tests.
181185
global.protractor = protractor;
182186
global.browser = browser;

0 commit comments

Comments
 (0)