feat(page): introduce page.setDefaultTimeout (#3854)

Method `page.setDefaultTimeout` overrides default 30 seconds timeout
for all `page.waitFor*` methods, including navigation and waiting
for selectors.

Fix #3319.
This commit is contained in:
Andrey Lushnikov
2019-01-28 17:16:12 -08:00
committed by GitHub
parent f2c968fdb8
commit a064a6341b
9 changed files with 195 additions and 40 deletions

View File

@@ -30,6 +30,7 @@ const {Coverage} = require('./Coverage');
const {Worker} = require('./Worker');
const {createJSHandle} = require('./JSHandle');
const {Accessibility} = require('./Accessibility');
const {TimeoutSettings} = require('./TimeoutSettings');
const writeFileAsync = helper.promisify(fs.writeFile);
class Page extends EventEmitter {
@@ -78,11 +79,12 @@ class Page extends EventEmitter {
this._target = target;
this._keyboard = new Keyboard(client);
this._mouse = new Mouse(client, this._keyboard);
this._timeoutSettings = new TimeoutSettings();
this._touchscreen = new Touchscreen(client, this._keyboard);
this._accessibility = new Accessibility(client);
this._networkManager = new NetworkManager(client);
/** @type {!FrameManager} */
this._frameManager = new FrameManager(client, frameTree, this, this._networkManager);
this._frameManager = new FrameManager(client, frameTree, this, this._networkManager, this._timeoutSettings);
this._networkManager.setFrameManager(this._frameManager);
this._emulationManager = new EmulationManager(client);
this._tracing = new Tracing(client);
@@ -268,7 +270,14 @@ class Page extends EventEmitter {
* @param {number} timeout
*/
setDefaultNavigationTimeout(timeout) {
this._frameManager.setDefaultNavigationTimeout(timeout);
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
}
/**
* @param {number} timeout
*/
setDefaultTimeout(timeout) {
this._timeoutSettings.setDefaultTimeout(timeout);
}
/**
@@ -664,7 +673,7 @@ class Page extends EventEmitter {
*/
async waitForRequest(urlOrPredicate, options = {}) {
const {
timeout = 30000
timeout = this._timeoutSettings.timeout(),
} = options;
return helper.waitForEvent(this._networkManager, Events.NetworkManager.Request, request => {
if (helper.isString(urlOrPredicate))
@@ -682,7 +691,7 @@ class Page extends EventEmitter {
*/
async waitForResponse(urlOrPredicate, options = {}) {
const {
timeout = 30000
timeout = this._timeoutSettings.timeout(),
} = options;
return helper.waitForEvent(this._networkManager, Events.NetworkManager.Response, response => {
if (helper.isString(urlOrPredicate))