Inroduce page.press (#96)
This patch: - introduces page.press() method - adds more input tests References #89
This commit is contained in:
parent
71f8c76f04
commit
febd747c5b
@ -44,6 +44,7 @@
|
|||||||
* [page.navigate(url, options)](#pagenavigateurl-options)
|
* [page.navigate(url, options)](#pagenavigateurl-options)
|
||||||
* [page.pdf(options)](#pagepdfoptions)
|
* [page.pdf(options)](#pagepdfoptions)
|
||||||
* [page.plainText()](#pageplaintext)
|
* [page.plainText()](#pageplaintext)
|
||||||
|
* [page.press(key[, options])](#pagepresskey-options)
|
||||||
* [page.reload(options)](#pagereloadoptions)
|
* [page.reload(options)](#pagereloadoptions)
|
||||||
* [page.screenshot([options])](#pagescreenshotoptions)
|
* [page.screenshot([options])](#pagescreenshotoptions)
|
||||||
* [page.setContent(html)](#pagesetcontenthtml)
|
* [page.setContent(html)](#pagesetcontenthtml)
|
||||||
@ -437,6 +438,14 @@ The `format` options are:
|
|||||||
#### page.plainText()
|
#### page.plainText()
|
||||||
- returns: <[Promise]<[string]>> Returns page's inner text.
|
- returns: <[Promise]<[string]>> Returns page's inner text.
|
||||||
|
|
||||||
|
#### page.press(key[, options])
|
||||||
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [KeyboardEvent.key](https://www.w3.org/TR/uievents-key/)
|
||||||
|
- `options` <[Object]>
|
||||||
|
- `text` <[string]> If specified, generates an input event with this text.
|
||||||
|
- returns: <[Promise]>
|
||||||
|
|
||||||
|
Shortcut for [`keyboard.down`](#keyboarddownkey) and [`keyboard.up`](#keyboardupkey).
|
||||||
|
|
||||||
#### page.reload(options)
|
#### page.reload(options)
|
||||||
- `options` <[Object]> Navigation parameters, same as in [page.navigate](#pagenavigateurl-options).
|
- `options` <[Object]> Navigation parameters, same as in [page.navigate](#pagenavigateurl-options).
|
||||||
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
- returns: <[Promise]<[Response]>> Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
|
||||||
|
@ -607,6 +607,14 @@ class Page extends EventEmitter {
|
|||||||
return this._keyboard.type(text);
|
return this._keyboard.type(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} text
|
||||||
|
* @param {!Object=} options
|
||||||
|
*/
|
||||||
|
async press(key, options) {
|
||||||
|
return this._keyboard.press(key, options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} selector
|
* @param {string} selector
|
||||||
* @return {!Promise<undefined>}
|
* @return {!Promise<undefined>}
|
||||||
|
20
test/test.js
20
test/test.js
@ -705,6 +705,26 @@ describe('Puppeteer', function() {
|
|||||||
await keyboard.press('Backspace');
|
await keyboard.press('Backspace');
|
||||||
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!');
|
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!');
|
||||||
}));
|
}));
|
||||||
|
it('should send a character with Page.press', SX(async function() {
|
||||||
|
await page.navigate(PREFIX + '/input/textarea.html');
|
||||||
|
await page.focus('textarea');
|
||||||
|
await page.press('a', {text: 'f'});
|
||||||
|
expect(await page.$('textarea', t => t.value)).toBe('f');
|
||||||
|
|
||||||
|
await page.evaluate(() => window.addEventListener('keydown', e => e.preventDefault(), true));
|
||||||
|
|
||||||
|
await page.press('a', {text: 'y'});
|
||||||
|
expect(await page.$('textarea', t => t.value)).toBe('f');
|
||||||
|
}));
|
||||||
|
it('should send a character with sendCharacter', SX(async function() {
|
||||||
|
await page.navigate(PREFIX + '/input/textarea.html');
|
||||||
|
await page.focus('textarea');
|
||||||
|
await page.keyboard.sendCharacter('嗨');
|
||||||
|
expect(await page.$('textarea', t => t.value)).toBe('嗨');
|
||||||
|
await page.evaluate(() => window.addEventListener('keydown', e => e.preventDefault(), true));
|
||||||
|
await page.keyboard.sendCharacter('a');
|
||||||
|
expect(await page.$('textarea', t => t.value)).toBe('嗨a');
|
||||||
|
}));
|
||||||
it('should report shiftKey', SX(async function(){
|
it('should report shiftKey', SX(async function(){
|
||||||
await page.navigate(PREFIX + '/input/keyboard.html');
|
await page.navigate(PREFIX + '/input/keyboard.html');
|
||||||
let keyboard = page.keyboard;
|
let keyboard = page.keyboard;
|
||||||
|
Loading…
Reference in New Issue
Block a user