Implement function as a part of a page.waitFor shortcut

This patch adds a function as a possible argument to
page.waitFor shortcut.

Fixes #91.
This commit is contained in:
Andrey Lushnikov
2017-07-27 17:09:28 -07:00
parent ff5ed1c738
commit bd898b7f56
4 changed files with 34 additions and 25 deletions

View File

@@ -270,16 +270,18 @@ class Frame {
}
/**
* @param {(string|number)} selectorOrTimeout
* @param {(string|number|function())} selectorOrTimeout
* @param {!Object=} options
* @return {!Promise}
*/
waitFor(selectorOrTimeout, options = {}) {
if (helper.isString(selectorOrTimeout))
return this.waitForSelector(selectorOrTimeout, options);
if (helper.isNumber(selectorOrTimeout))
return new Promise(fulfill => setTimeout(fulfill, selectorOrTimeout));
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrTimeout)));
waitFor(selectorOrFunctionOrTimeout, options = {}) {
if (helper.isString(selectorOrFunctionOrTimeout))
return this.waitForSelector(selectorOrFunctionOrTimeout, options);
if (helper.isNumber(selectorOrFunctionOrTimeout))
return new Promise(fulfill => setTimeout(fulfill, selectorOrFunctionOrTimeout));
if (typeof selectorOrFunctionOrTimeout === 'function')
return this.waitForFunction(selectorOrFunctionOrTimeout, options);
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrFunctionOrTimeout)));
}
/**

View File

@@ -554,12 +554,12 @@ class Page extends EventEmitter {
}
/**
* @param {string} selectorOrTimeout
* @param {(string|number|function())} selectorOrTimeout
* @param {!Object=} options
* @return {!Promise<undefined>}
* @return {!Promise}
*/
waitFor(selectorOrTimeout, options) {
return this.mainFrame().waitFor(selectorOrTimeout, options);
waitFor(selectorOrFunctionOrTimeout, options = {}) {
return this.mainFrame().waitFor(selectorOrFunctionOrTimeout, options);
}
/**