Improve documentation for the page.waitFor method.

Fixes #109.
This commit is contained in:
Andrey Lushnikov 2017-07-25 08:46:11 -07:00
parent 877f06aacb
commit b564029589
3 changed files with 26 additions and 21 deletions

View File

@ -58,7 +58,7 @@
+ [page.uploadFile(selector, ...filePaths)](#pageuploadfileselector-filepaths)
+ [page.url()](#pageurl)
+ [page.viewport()](#pageviewport)
+ [page.waitFor(target[, options])](#pagewaitfortarget-options)
+ [page.waitFor(selectorOrTimeout[, options])](#pagewaitforselectorortimeout-options)
+ [page.waitForNavigation(options)](#pagewaitfornavigationoptions)
+ [page.waitForSelector(selector[, options])](#pagewaitforselectorselector-options)
* [class: Keyboard](#class-keyboard)
@ -87,7 +87,7 @@
+ [frame.name()](#framename)
+ [frame.parentFrame()](#frameparentframe)
+ [frame.url()](#frameurl)
+ [frame.waitFor(target[, options])](#framewaitfortarget-options)
+ [frame.waitFor(selectorOrTimeout[, options])](#framewaitforselectorortimeout-options)
+ [frame.waitForSelector(selector[, options])](#framewaitforselectorselector-options)
* [class: Request](#class-request)
+ [request.headers](#requestheaders)
@ -603,12 +603,17 @@ This is a shortcut for [page.mainFrame().url()](#frameurl)
#### page.viewport()
- returns: <[Object]> An object with the save fields as described in [page.setViewport](#pagesetviewportviewport)
#### page.waitFor(target[, options])
- `target` <[string]|[number]> A target to wait for.
- `options` <[Object]> Optional waiting parameters.
#### page.waitFor(selectorOrTimeout[, options])
- `selectorOrTimeout` <[string]|[number]> A selector or timeout to wait for
- `options` <[Object]> Optional waiting parameters
- returns: <[Promise]>
Shortcut for [page.mainFrame().waitFor()](#framewaitfortargetoptions).
This method behaves differently with respect to the type of the first parameter:
- if `selectorOrTimeout` is a `string`, than the first argument is treated as a selector to wait for and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselectoroptions)
- if `selectorOrTimeout` is a `number`, than the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout
- otherwise, an exception is thrown
The method is a shortcut for [page.mainFrame().waitFor()](#framewaitfortargetoptions).
#### page.waitForNavigation(options)
- `options` <[Object]> Navigation parameters, same as in [page.navigate](#pagenavigateurl-options).
@ -837,14 +842,14 @@ Returns frame's name as specified in the tag.
Returns frame's url.
#### frame.waitFor(target[, options])
- `target` <[string]|[number]> A target to wait for
#### frame.waitFor(selectorOrTimeout[, options])
- `selectorOrTimeout` <[string]|[number]> A selector or timeout to wait for
- `options` <[Object]> Optional waiting parameters
- returns: <[Promise]>
This method behaves differently wrt the type of the first parameter:
- if `target` is a `string`, than target is treated as a selector to wait for and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselectoroptions)
- if `target` is a `number`, than target is treated as timeout in milliseconds and the method returns a promise which resolves after the timeout
This method behaves differently with respect to the type of the first parameter:
- if `selectorOrTimeout` is a `string`, than the first argument is treated as a selector to wait for and the method is a shortcut for [frame.waitForSelector](#framewaitforselectorselectoroptions)
- if `selectorOrTimeout` is a `number`, than the first argument is treated as a timeout in milliseconds and the method returns a promise which resolves after the timeout
- otherwise, an exception is thrown
#### frame.waitForSelector(selector[, options])

View File

@ -252,16 +252,16 @@ class Frame {
}
/**
* @param {(string|number)} target
* @param {(string|number)} selectorOrTimeout
* @param {!Object=} options
* @return {!Promise}
*/
waitFor(target, options = {}) {
if (typeof target === 'string' || target instanceof String)
return this.waitForSelector(target, options);
if (typeof target === 'number' || target instanceof Number)
return new Promise(fulfill => setTimeout(fulfill, target));
return Promise.reject(new Error('Unsupported target type: ' + (typeof target)));
waitFor(selectorOrTimeout, options = {}) {
if (typeof selectorOrTimeout === 'string' || selectorOrTimeout instanceof String)
return this.waitForSelector(selectorOrTimeout, options);
if (typeof selectorOrTimeout === 'number' || selectorOrTimeout instanceof Number)
return new Promise(fulfill => setTimeout(fulfill, selectorOrTimeout));
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrTimeout)));
}
/**

View File

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