diff --git a/docs/referenceConf.js b/docs/referenceConf.js index 15e96bfb0..c5515c766 100644 --- a/docs/referenceConf.js +++ b/docs/referenceConf.js @@ -128,10 +128,14 @@ exports.config = { // body, but is necessary if ng-app is on a descendant of . 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 diff --git a/docs/timeouts.md b/docs/timeouts.md index 47d6f2db8..3aeb8813b 100644 --- a/docs/timeouts.md +++ b/docs/timeouts.md @@ -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** @@ -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 diff --git a/lib/configParser.js b/lib/configParser.js index f57e40a25..4389e54a6 100644 --- a/lib/configParser.js +++ b/lib/configParser.js @@ -25,6 +25,7 @@ var ConfigParser = function() { multiCapabilities: [], rootElement: 'body', allScriptsTimeout: 11000, + getPageTimeout: 10000, params: {}, framework: 'jasmine', jasmineNodeOpts: { diff --git a/lib/protractor.js b/lib/protractor.js index 7ba6fe880..25bbce83a 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -24,6 +24,7 @@ var STACK_SUBSTRINGS_TO_FILTER = [ ]; var DEFAULT_RESET_URL = 'data:text/html,'; +var DEFAULT_GET_PAGE_TIMEOUT = 10000; /* * Mix in other webdriver functionality to be accessible via protractor. @@ -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. * @@ -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); @@ -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) { diff --git a/lib/runner.js b/lib/runner.js index 504f7ad30..80d04a102 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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;