mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
api docs and fix timeout
This commit is contained in:
parent
ac47765ce6
commit
0dfe10cdd2
15
docs/api.md
15
docs/api.md
@ -44,6 +44,7 @@
|
||||
- [class: Keyboard](#class-keyboard)
|
||||
* [keyboard.press(key)](#keyboardpresskey)
|
||||
* [keyboard.release(key)](#keyboardreleasekey)
|
||||
* [keyboard.sendCharacter(char)](#keyboardsendcharacterchar)
|
||||
* [keyboard.type(text)](#keyboardtypetext)
|
||||
- [class: Dialog](#class-dialog)
|
||||
* [dialog.accept([promptText])](#dialogacceptprompttext)
|
||||
@ -387,16 +388,28 @@ Shortcut for [page.mainFrame().waitFor(selector)](#framewaitforselector).
|
||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [KeyboardEvent.key](https://www.w3.org/TR/uievents-key/)
|
||||
- returns <[Promise]>
|
||||
|
||||
Dispatches a `keydown` event.
|
||||
This does not send input events. To type characters into a text field, use [keyboard.type(text)](#keyboardtypetext)
|
||||
|
||||
#### keyboard.release(key)
|
||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [KeyboardEvent.key](https://www.w3.org/TR/uievents-key/)
|
||||
- `key` <[string]> Name of key to release, such as `ArrowLeft`. See [KeyboardEvent.key](https://www.w3.org/TR/uievents-key/)
|
||||
- returns <[Promise]>
|
||||
|
||||
Dispatches a `keyup` event.
|
||||
|
||||
#### keyboard.sendCharacter(char)
|
||||
- `char` <[string]> Character to send into the page.
|
||||
- returns <[Promise]>
|
||||
|
||||
Dispatches a `keypress` and `input` event. This does not send a `keydown` or `keyup` event.
|
||||
|
||||
#### keyboard.type(text)
|
||||
- `text` <[string]> Text to type into the page
|
||||
- returns <[Promise]>
|
||||
|
||||
Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
|
||||
This is the suggested way to type printable characters.
|
||||
|
||||
### class: Dialog
|
||||
#### dialog.accept([promptText])
|
||||
- `promptText` <[string]> A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt.
|
||||
|
@ -173,10 +173,15 @@ class Keyboard {
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let char = text.charAt(i);
|
||||
let promise = this._client.send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true});
|
||||
// make sure the first evaluate was run
|
||||
await this._client.send('Runtime.evaluate', { expression: '1', returnByValue: true});
|
||||
this.press(char);
|
||||
if (!(await promise).result.value)
|
||||
this.sendCharacter(char);
|
||||
await this.release(char);
|
||||
if (i < text.length - 1)
|
||||
this.release(char);
|
||||
else
|
||||
await this.release(char);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -680,6 +680,8 @@ describe('Puppeteer', function() {
|
||||
expect(await page.evaluate(() => getResult())).toBe('Keyup: Shift 16 0');
|
||||
}));
|
||||
it('should report altKey', SX(async function(){
|
||||
await page.navigate(PREFIX + '/input/keyboard.html');
|
||||
let keyboard = page.keyboard();
|
||||
await keyboard.press('Alt');
|
||||
expect(await page.evaluate(() => getResult())).toBe('Keydown: Alt 18 1');
|
||||
await keyboard.press('a');
|
||||
@ -690,6 +692,8 @@ describe('Puppeteer', function() {
|
||||
expect(await page.evaluate(() => getResult())).toBe('Keyup: Alt 18 0');
|
||||
}));
|
||||
it('should report multiple modifiers', SX(async function(){
|
||||
await page.navigate(PREFIX + '/input/keyboard.html');
|
||||
let keyboard = page.keyboard();
|
||||
await keyboard.press('Control');
|
||||
expect(await page.evaluate(() => getResult())).toBe('Keydown: Control 17 2');
|
||||
await keyboard.press('Meta');
|
||||
|
Loading…
Reference in New Issue
Block a user