chore: implement Bidi keyboard (#10417)

This commit is contained in:
jrandolf 2023-06-19 17:44:39 +02:00 committed by GitHub
parent 769dd593ab
commit 3ba7fba838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 510 additions and 80 deletions

View File

@ -92,6 +92,7 @@ sidebar_label: API
| [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | | | [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | |
| [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript | | [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript |
| [JSCoverageOptions](./puppeteer.jscoverageoptions.md) | Set of configurable options for JS coverage. | | [JSCoverageOptions](./puppeteer.jscoverageoptions.md) | Set of configurable options for JS coverage. |
| [KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md) | |
| [KeyDownOptions](./puppeteer.keydownoptions.md) | | | [KeyDownOptions](./puppeteer.keydownoptions.md) | |
| [LaunchOptions](./puppeteer.launchoptions.md) | Generic launch options that can be passed when launching any browser. | | [LaunchOptions](./puppeteer.launchoptions.md) | Generic launch options that can be passed when launching any browser. |
| [LocatorEventObject](./puppeteer.locatoreventobject.md) | | | [LocatorEventObject](./puppeteer.locatoreventobject.md) | |
@ -118,7 +119,6 @@ sidebar_label: API
| [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. | | [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. |
| [SnapshotOptions](./puppeteer.snapshotoptions.md) | | | [SnapshotOptions](./puppeteer.snapshotoptions.md) | |
| [TracingOptions](./puppeteer.tracingoptions.md) | | | [TracingOptions](./puppeteer.tracingoptions.md) | |
| [TypeOptions](./puppeteer.typeoptions.md) | |
| [Viewport](./puppeteer.viewport.md) | Sets the viewport of the page. | | [Viewport](./puppeteer.viewport.md) | Sets the viewport of the page. |
| [WaitForOptions](./puppeteer.waitforoptions.md) | | | [WaitForOptions](./puppeteer.waitforoptions.md) | |
| [WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md) | | | [WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md) | |

View File

@ -12,16 +12,16 @@ To press a special key, like `Control` or `ArrowDown`, use [ElementHandle.press(
```typescript ```typescript
class ElementHandle { class ElementHandle {
type(text: string, options?: Readonly<TypeOptions>): Promise<void>; type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
} }
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | --------------------------------------------------------- | -------------------------------------------------- | | --------- | ------------------------------------------------------------------------- | -------------------------------------------------- |
| text | string | | | text | string | |
| options | Readonly&lt;[TypeOptions](./puppeteer.typeoptions.md)&gt; | _(Optional)_ Delay in milliseconds. Defaults to 0. | | options | Readonly&lt;[KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md)&gt; | _(Optional)_ Delay in milliseconds. Defaults to 0. |
**Returns:** **Returns:**

View File

@ -13,18 +13,18 @@ class Frame {
type( type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void>; ): Promise<void>;
} }
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| selector | string | the selector for the element to type into. If there are multiple the first will be used. | | selector | string | the selector for the element to type into. If there are multiple the first will be used. |
| text | string | text to type into the element | | text | string | text to type into the element |
| options | Readonly&lt;[TypeOptions](./puppeteer.typeoptions.md)&gt; | _(Optional)_ takes one option, <code>delay</code>, which sets the time to wait between key presses in milliseconds. Defaults to <code>0</code>. | | options | Readonly&lt;[KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md)&gt; | _(Optional)_ takes one option, <code>delay</code>, which sets the time to wait between key presses in milliseconds. Defaults to <code>0</code>. |
**Returns:** **Returns:**

View File

@ -10,16 +10,16 @@ Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in t
```typescript ```typescript
class Keyboard { class Keyboard {
type(text: string, options?: Readonly<TypeOptions>): Promise<void>; type(text: string, options?: Readonly<KeyboardTypeOptions>): Promise<void>;
} }
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| text | string | A text to type into a focused element. | | text | string | A text to type into a focused element. |
| options | Readonly&lt;[TypeOptions](./puppeteer.typeoptions.md)&gt; | _(Optional)_ An object of options. Accepts delay which, if specified, is the time to wait between <code>keydown</code> and <code>keyup</code> in milliseconds. Defaults to 0. | | options | Readonly&lt;[KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md)&gt; | _(Optional)_ An object of options. Accepts delay which, if specified, is the time to wait between <code>keydown</code> and <code>keyup</code> in milliseconds. Defaults to 0. |
**Returns:** **Returns:**

View File

@ -1,13 +1,13 @@
--- ---
sidebar_label: TypeOptions sidebar_label: KeyboardTypeOptions
--- ---
# TypeOptions interface # KeyboardTypeOptions interface
#### Signature: #### Signature:
```typescript ```typescript
export interface TypeOptions export interface KeyboardTypeOptions
``` ```
## Properties ## Properties

View File

@ -7,7 +7,7 @@ sidebar_label: KeyPressOptions
#### Signature: #### Signature:
```typescript ```typescript
export type KeyPressOptions = KeyDownOptions & TypeOptions; export type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;
``` ```
**References:** [KeyDownOptions](./puppeteer.keydownoptions.md), [TypeOptions](./puppeteer.typeoptions.md) **References:** [KeyDownOptions](./puppeteer.keydownoptions.md), [KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md)

View File

@ -15,18 +15,18 @@ class Page {
type( type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void>; ): Promise<void>;
} }
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| selector | string | A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) of an element to type into. If there are multiple elements satisfying the selector, the first will be used. | | selector | string | A [selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) of an element to type into. If there are multiple elements satisfying the selector, the first will be used. |
| text | string | A text to type into a focused element. | | text | string | A text to type into a focused element. |
| options | Readonly&lt;[TypeOptions](./puppeteer.typeoptions.md)&gt; | _(Optional)_ have property <code>delay</code> which is the Time to wait between key presses in milliseconds. Defaults to <code>0</code>. | | options | Readonly&lt;[KeyboardTypeOptions](./puppeteer.keyboardtypeoptions.md)&gt; | _(Optional)_ have property <code>delay</code> which is the Time to wait between key presses in milliseconds. Defaults to <code>0</code>. |
**Returns:** **Returns:**

View File

@ -34,7 +34,11 @@ import {isString, withSourcePuppeteerURLIfNone} from '../common/util.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js'; import {AsyncIterableUtil} from '../util/AsyncIterableUtil.js';
import {KeyPressOptions, MouseClickOptions, TypeOptions} from './Input.js'; import {
KeyPressOptions,
MouseClickOptions,
KeyboardTypeOptions,
} from './Input.js';
import {JSHandle} from './JSHandle.js'; import {JSHandle} from './JSHandle.js';
import {ScreenshotOptions} from './Page.js'; import {ScreenshotOptions} from './Page.js';
@ -844,7 +848,10 @@ export class ElementHandle<
* *
* @param options - Delay in milliseconds. Defaults to 0. * @param options - Delay in milliseconds. Defaults to 0.
*/ */
async type(text: string, options?: Readonly<TypeOptions>): Promise<void>; async type(
text: string,
options?: Readonly<KeyboardTypeOptions>
): Promise<void>;
async type(): Promise<void> { async type(): Promise<void> {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }

View File

@ -35,7 +35,7 @@ import {
} from '../common/types.js'; } from '../common/types.js';
import {TaskManager} from '../common/WaitTask.js'; import {TaskManager} from '../common/WaitTask.js';
import {TypeOptions} from './Input.js'; import {KeyboardTypeOptions} from './Input.js';
import {JSHandle} from './JSHandle.js'; import {JSHandle} from './JSHandle.js';
import {Locator} from './Locator.js'; import {Locator} from './Locator.js';
@ -83,7 +83,7 @@ export interface Realm {
type( type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void>; ): Promise<void>;
} }
@ -885,7 +885,7 @@ export class Frame {
type( type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void> { ): Promise<void> {
return this.isolatedRealm().type(selector, text, options); return this.isolatedRealm().type(selector, text, options);
} }

View File

@ -24,21 +24,27 @@ import {Point} from './ElementHandle.js';
* @public * @public
*/ */
export interface KeyDownOptions { export interface KeyDownOptions {
/**
* @deprecated Do not use. This is automatically handled.
*/
text?: string; text?: string;
/**
* @deprecated Do not use. This is automatically handled.
*/
commands?: string[]; commands?: string[];
} }
/** /**
* @public * @public
*/ */
export interface TypeOptions { export interface KeyboardTypeOptions {
delay?: number; delay?: number;
} }
/** /**
* @public * @public
*/ */
export type KeyPressOptions = KeyDownOptions & TypeOptions; export type KeyPressOptions = KeyDownOptions & KeyboardTypeOptions;
/** /**
* Keyboard provides an api for managing a virtual keyboard. * Keyboard provides an api for managing a virtual keyboard.
@ -175,7 +181,10 @@ export class Keyboard {
* if specified, is the time to wait between `keydown` and `keyup` in milliseconds. * if specified, is the time to wait between `keydown` and `keyup` in milliseconds.
* Defaults to 0. * Defaults to 0.
*/ */
async type(text: string, options?: Readonly<TypeOptions>): Promise<void>; async type(
text: string,
options?: Readonly<KeyboardTypeOptions>
): Promise<void>;
async type(): Promise<void> { async type(): Promise<void> {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }

View File

@ -71,7 +71,7 @@ import type {
FrameAddStyleTagOptions, FrameAddStyleTagOptions,
FrameWaitForFunctionOptions, FrameWaitForFunctionOptions,
} from './Frame.js'; } from './Frame.js';
import {Keyboard, Mouse, Touchscreen, TypeOptions} from './Input.js'; import {Keyboard, Mouse, Touchscreen, KeyboardTypeOptions} from './Input.js';
import type {JSHandle} from './JSHandle.js'; import type {JSHandle} from './JSHandle.js';
import {Locator} from './Locator.js'; import {Locator} from './Locator.js';
@ -2556,7 +2556,7 @@ export class Page extends EventEmitter {
type( type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void> { ): Promise<void> {
return this.mainFrame().type(selector, text, options); return this.mainFrame().type(selector, text, options);
} }

View File

@ -24,7 +24,7 @@ import {
Offset, Offset,
Point, Point,
} from '../api/ElementHandle.js'; } from '../api/ElementHandle.js';
import {KeyPressOptions, TypeOptions} from '../api/Input.js'; import {KeyPressOptions, KeyboardTypeOptions} from '../api/Input.js';
import {Page, ScreenshotOptions} from '../api/Page.js'; import {Page, ScreenshotOptions} from '../api/Page.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
@ -447,7 +447,7 @@ export class CDPElementHandle<
override async type( override async type(
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void> { ): Promise<void> {
await this.focus(); await this.focus();
await this.#page.keyboard.type(text, options); await this.#page.keyboard.type(text, options);

View File

@ -28,7 +28,7 @@ import {
MouseOptions, MouseOptions,
MouseWheelOptions, MouseWheelOptions,
Touchscreen, Touchscreen,
TypeOptions, KeyboardTypeOptions,
} from '../api/Input.js'; } from '../api/Input.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
@ -183,7 +183,7 @@ export class CDPKeyboard extends Keyboard {
override async type( override async type(
text: string, text: string,
options: Readonly<TypeOptions> = {} options: Readonly<KeyboardTypeOptions> = {}
): Promise<void> { ): Promise<void> {
const delay = options.delay || undefined; const delay = options.delay || undefined;
for (const char of text) { for (const char of text) {

View File

@ -18,7 +18,7 @@ import {Protocol} from 'devtools-protocol';
import type {ClickOptions, ElementHandle} from '../api/ElementHandle.js'; import type {ClickOptions, ElementHandle} from '../api/ElementHandle.js';
import {Realm} from '../api/Frame.js'; import {Realm} from '../api/Frame.js';
import {TypeOptions} from '../api/Input.js'; import {KeyboardTypeOptions} from '../api/Input.js';
import {JSHandle} from '../api/JSHandle.js'; import {JSHandle} from '../api/JSHandle.js';
import {assert} from '../util/assert.js'; import {assert} from '../util/assert.js';
import {Deferred} from '../util/Deferred.js'; import {Deferred} from '../util/Deferred.js';
@ -350,7 +350,7 @@ export class IsolatedWorld implements Realm {
async type( async type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void> { ): Promise<void> {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, `No element found for selector: ${selector}`); assert(handle, `No element found for selector: ${selector}`);

View File

@ -20,7 +20,9 @@ import {
ElementHandle as BaseElementHandle, ElementHandle as BaseElementHandle,
ClickOptions, ClickOptions,
} from '../../api/ElementHandle.js'; } from '../../api/ElementHandle.js';
import {KeyPressOptions, KeyboardTypeOptions} from '../../api/Input.js';
import {assert} from '../../util/assert.js'; import {assert} from '../../util/assert.js';
import {KeyInput} from '../USKeyboardLayout.js';
import {Frame} from './Frame.js'; import {Frame} from './Frame.js';
import {JSHandle} from './JSHandle.js'; import {JSHandle} from './JSHandle.js';
@ -143,4 +145,20 @@ export class ElementHandle<
await this.scrollIntoViewIfNeeded(); await this.scrollIntoViewIfNeeded();
await this.#frame.page().touchscreen.touchEnd(); await this.#frame.page().touchscreen.touchEnd();
} }
override async type(
text: string,
options?: Readonly<KeyboardTypeOptions>
): Promise<void> {
await this.focus();
await this.#frame.page().keyboard.type(text, options);
}
override async press(
key: KeyInput,
options?: Readonly<KeyPressOptions>
): Promise<void> {
await this.focus();
await this.#frame.page().keyboard.press(key, options);
}
} }

View File

@ -18,23 +18,299 @@ import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import {Point} from '../../api/ElementHandle.js'; import {Point} from '../../api/ElementHandle.js';
import { import {
Keyboard as BaseKeyboard,
Mouse as BaseMouse, Mouse as BaseMouse,
Touchscreen as BaseTouchscreen,
KeyDownOptions,
KeyPressOptions,
KeyboardTypeOptions,
MouseButton, MouseButton,
MouseClickOptions, MouseClickOptions,
MouseMoveOptions, MouseMoveOptions,
MouseOptions, MouseOptions,
MouseWheelOptions, MouseWheelOptions,
Touchscreen as BaseTouchscreen,
} from '../../api/Input.js'; } from '../../api/Input.js';
import {KeyInput} from '../USKeyboardLayout.js';
import {BrowsingContext} from './BrowsingContext.js'; import {BrowsingContext} from './BrowsingContext.js';
const enum InputId { const enum InputId {
Mouse = '__puppeteer_mouse', Mouse = '__puppeteer_mouse',
Keyboard = '__puppeteer_keyboard',
Wheel = '__puppeteer_wheel', Wheel = '__puppeteer_wheel',
Finger = '__puppeteer_finger', Finger = '__puppeteer_finger',
} }
const getBidiKeyValue = (key: string) => {
switch (key) {
case '\n':
key = 'Enter';
break;
}
// Measures the number of code points rather than UTF-16 code units.
if ([...key].length === 1) {
return key;
}
switch (key) {
case 'Unidentified':
return '\uE000';
case 'Cancel':
return '\uE001';
case 'Help':
return '\uE002';
case 'Backspace':
return '\uE003';
case 'Tab':
return '\uE004';
case 'Clear':
return '\uE005';
case 'Return':
return '\uE006';
case 'Enter':
return '\uE007';
case 'Shift':
return '\uE008';
case 'Control':
return '\uE009';
case 'Alt':
return '\uE00A';
case 'Pause':
return '\uE00B';
case 'Escape':
return '\uE00C';
case ' ':
return '\uE00D';
case 'PageUp':
return '\uE00E';
case 'PageDown':
return '\uE00F';
case 'End':
return '\uE010';
case 'Home':
return '\uE011';
case 'ArrowLeft':
return '\uE012';
case 'ArrowUp':
return '\uE013';
case 'ArrowRight':
return '\uE014';
case 'ArrowDown':
return '\uE015';
case 'Insert':
return '\uE016';
case 'Delete':
return '\uE017';
case ';':
return '\uE018';
case '=':
return '\uE019';
case '0':
return '\uE01A';
case '1':
return '\uE01B';
case '2':
return '\uE01C';
case '3':
return '\uE01D';
case '4':
return '\uE01E';
case '5':
return '\uE01F';
case '6':
return '\uE020';
case '7':
return '\uE021';
case '8':
return '\uE022';
case '9':
return '\uE023';
case '*':
return '\uE024';
case '+':
return '\uE025';
case ',':
return '\uE026';
case '-':
return '\uE027';
case '.':
return '\uE028';
case '/':
return '\uE029';
case 'F1':
return '\uE031';
case 'F2':
return '\uE032';
case 'F3':
return '\uE033';
case 'F4':
return '\uE034';
case 'F5':
return '\uE035';
case 'F6':
return '\uE036';
case 'F7':
return '\uE037';
case 'F8':
return '\uE038';
case 'F9':
return '\uE039';
case 'F10':
return '\uE03A';
case 'F11':
return '\uE03B';
case 'F12':
return '\uE03C';
case 'Meta':
return '\uE03D';
case 'ZenkakuHankaku':
return '\uE040';
default:
throw new Error(`Unknown key: "${key}"`);
}
};
/**
* @internal
*/
export class Keyboard extends BaseKeyboard {
#context: BrowsingContext;
/**
* @internal
*/
constructor(context: BrowsingContext) {
super();
this.#context = context;
}
override async down(
key: KeyInput,
options?: Readonly<KeyDownOptions>
): Promise<void> {
if (options) {
throw new Error('KeyDownOptions are not supported');
}
await this.#context.connection.send('input.performActions', {
context: this.#context.id,
actions: [
{
type: Bidi.Input.SourceActionsType.Key,
id: InputId.Keyboard,
actions: [
{
type: Bidi.Input.ActionType.KeyDown,
value: getBidiKeyValue(key),
},
],
},
],
});
}
override async up(key: KeyInput): Promise<void> {
await this.#context.connection.send('input.performActions', {
context: this.#context.id,
actions: [
{
type: Bidi.Input.SourceActionsType.Key,
id: InputId.Keyboard,
actions: [
{
type: Bidi.Input.ActionType.KeyUp,
value: getBidiKeyValue(key),
},
],
},
],
});
}
override async press(
key: KeyInput,
options: Readonly<KeyPressOptions> = {}
): Promise<void> {
const {delay = 0} = options;
const actions: Bidi.Input.KeySourceAction[] = [
{
type: Bidi.Input.ActionType.KeyDown,
value: getBidiKeyValue(key),
},
];
if (delay > 0) {
actions.push({
type: Bidi.Input.ActionType.Pause,
duration: delay,
});
}
actions.push({
type: Bidi.Input.ActionType.KeyUp,
value: getBidiKeyValue(key),
});
await this.#context.connection.send('input.performActions', {
context: this.#context.id,
actions: [
{
type: Bidi.Input.SourceActionsType.Key,
id: InputId.Keyboard,
actions,
},
],
});
}
override async type(
text: string,
options: Readonly<KeyboardTypeOptions> = {}
): Promise<void> {
const {delay = 0} = options;
// This spread separates the characters into code points rather than UTF-16
// code units.
const values = [...text].map(getBidiKeyValue);
const actions: Bidi.Input.KeySourceAction[] = [];
if (delay <= 0) {
for (const value of values) {
actions.push(
{
type: Bidi.Input.ActionType.KeyDown,
value,
},
{
type: Bidi.Input.ActionType.KeyUp,
value,
}
);
}
} else {
for (const value of values) {
actions.push(
{
type: Bidi.Input.ActionType.KeyDown,
value,
},
{
type: Bidi.Input.ActionType.Pause,
duration: delay,
},
{
type: Bidi.Input.ActionType.KeyUp,
value,
}
);
}
}
await this.#context.connection.send('input.performActions', {
context: this.#context.id,
actions: [
{
type: Bidi.Input.SourceActionsType.Key,
id: InputId.Keyboard,
actions,
},
],
});
}
}
/** /**
* @internal * @internal
*/ */

View File

@ -58,7 +58,7 @@ import {Connection} from './Connection.js';
import {Frame} from './Frame.js'; import {Frame} from './Frame.js';
import {HTTPRequest} from './HTTPRequest.js'; import {HTTPRequest} from './HTTPRequest.js';
import {HTTPResponse} from './HTTPResponse.js'; import {HTTPResponse} from './HTTPResponse.js';
import {Mouse, Touchscreen} from './Input.js'; import {Keyboard, Mouse, Touchscreen} from './Input.js';
import {NetworkManager} from './NetworkManager.js'; import {NetworkManager} from './NetworkManager.js';
import {getBidiHandle} from './Realm.js'; import {getBidiHandle} from './Realm.js';
import {BidiSerializer} from './Serializer.js'; import {BidiSerializer} from './Serializer.js';
@ -130,6 +130,7 @@ export class Page extends PageBase {
#emulationManager: EmulationManager; #emulationManager: EmulationManager;
#mouse: Mouse; #mouse: Mouse;
#touchscreen: Touchscreen; #touchscreen: Touchscreen;
#keyboard: Keyboard;
constructor(browserContext: BrowserContext, info: {context: string}) { constructor(browserContext: BrowserContext, info: {context: string}) {
super(); super();
@ -162,6 +163,7 @@ export class Page extends PageBase {
); );
this.#mouse = new Mouse(this.mainFrame().context()); this.#mouse = new Mouse(this.mainFrame().context());
this.#touchscreen = new Touchscreen(this.mainFrame().context()); this.#touchscreen = new Touchscreen(this.mainFrame().context());
this.#keyboard = new Keyboard(this.mainFrame().context());
} }
override get accessibility(): Accessibility { override get accessibility(): Accessibility {
@ -184,6 +186,10 @@ export class Page extends PageBase {
return this.#touchscreen; return this.#touchscreen;
} }
override get keyboard(): Keyboard {
return this.#keyboard;
}
override browser(): Browser { override browser(): Browser {
return this.#browserContext.browser(); return this.#browserContext.browser();
} }

View File

@ -16,7 +16,7 @@
import {ClickOptions, ElementHandle} from '../../api/ElementHandle.js'; import {ClickOptions, ElementHandle} from '../../api/ElementHandle.js';
import {Realm as RealmBase} from '../../api/Frame.js'; import {Realm as RealmBase} from '../../api/Frame.js';
import {TypeOptions} from '../../api/Input.js'; import {KeyboardTypeOptions} from '../../api/Input.js';
import {JSHandle as BaseJSHandle} from '../../api/JSHandle.js'; import {JSHandle as BaseJSHandle} from '../../api/JSHandle.js';
import {assert} from '../../util/assert.js'; import {assert} from '../../util/assert.js';
import {TimeoutSettings} from '../TimeoutSettings.js'; import {TimeoutSettings} from '../TimeoutSettings.js';
@ -269,7 +269,7 @@ export class Sandbox implements RealmBase {
async type( async type(
selector: string, selector: string,
text: string, text: string,
options?: Readonly<TypeOptions> options?: Readonly<KeyboardTypeOptions>
): Promise<void> { ): Promise<void> {
const handle = await this.$(selector); const handle = await this.$(selector);
assert(handle, `No element found for selector: ${selector}`); assert(handle, `No element found for selector: ${selector}`);

View File

@ -455,6 +455,18 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["PASS"] "expectations": ["PASS"]
}, },
{
"testIdPattern": "[click.spec] Page.click should select the text by triple clicking",
"platforms": ["linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[click.spec] Page.click should select the text by triple clicking",
"platforms": ["darwin"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
},
{ {
"testIdPattern": "[Connection.spec] WebDriver BiDi Connection should work", "testIdPattern": "[Connection.spec] WebDriver BiDi Connection should work",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -707,6 +719,66 @@
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["FAIL", "PASS"] "expectations": ["FAIL", "PASS"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should move with the arrow keys",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should not type canceled events",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send a character with ElementHandle.press",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send proper codes while typing",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should send proper codes while typing with shift",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should specify repeat property",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type emoji",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should type into a textarea",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes", "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -809,6 +881,36 @@
"parameters": ["firefox", "webDriverBiDi"], "parameters": ["firefox", "webDriverBiDi"],
"expectations": ["SKIP"] "expectations": ["SKIP"]
}, },
{
"testIdPattern": "[locator.spec] Locator Locator.change should override pre-filled inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for contenteditable",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for pre-filled inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work if the input becomes enabled later",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[navigation.spec] navigation \"after each\" hook for \"should work with both domcontentloaded and load\"", "testIdPattern": "[navigation.spec] navigation \"after each\" hook for \"should work with both domcontentloaded and load\"",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1065,7 +1167,7 @@
"testIdPattern": "[queryhandler.spec] Query handler tests Text selectors in Page should clear caches", "testIdPattern": "[queryhandler.spec] Query handler tests Text selectors in Page should clear caches",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"], "parameters": ["webDriverBiDi"],
"expectations": ["FAIL"] "expectations": ["PASS"]
}, },
{ {
"testIdPattern": "[requestinterception-experimental.spec] *", "testIdPattern": "[requestinterception-experimental.spec] *",
@ -1365,7 +1467,7 @@
"testIdPattern": "[click.spec] Page.click should click offscreen buttons", "testIdPattern": "[click.spec] Page.click should click offscreen buttons",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"], "parameters": ["firefox", "webDriverBiDi"],
"expectations": ["TIMEOUT"] "expectations": ["TIMEOUT", "FAIL"]
}, },
{ {
"testIdPattern": "[click.spec] Page.click should click on checkbox label and toggle", "testIdPattern": "[click.spec] Page.click should click on checkbox label and toggle",
@ -1415,6 +1517,12 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL", "PASS"] "expectations": ["FAIL", "PASS"]
}, },
{
"testIdPattern": "[click.spec] Page.click should select the text by triple clicking",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{ {
"testIdPattern": "[cookies.spec] Cookie specs Page.cookies should get cookies from multiple urls", "testIdPattern": "[cookies.spec] Cookie specs Page.cookies should get cookies from multiple urls",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1823,18 +1931,48 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the meta key",
"platforms": ["darwin"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey", "testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["linux", "win32"], "platforms": ["linux", "win32"],
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[keyboard.spec] Keyboard should press the metaKey",
"platforms": ["darwin"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should report shiftKey", "testIdPattern": "[keyboard.spec] Keyboard should report shiftKey",
"platforms": ["darwin"], "platforms": ["darwin"],
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should report shiftKey",
"platforms": ["linux"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter", "testIdPattern": "[keyboard.spec] Keyboard should send a character with sendCharacter",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1865,6 +2003,12 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["FAIL"] "expectations": ["FAIL"]
}, },
{
"testIdPattern": "[keyboard.spec] Keyboard should type all kinds of characters",
"platforms": ["linux"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{ {
"testIdPattern": "[keyboard.spec] Keyboard should type emoji", "testIdPattern": "[keyboard.spec] Keyboard should type emoji",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1997,36 +2141,6 @@
"parameters": ["firefox", "webDriverBiDi"], "parameters": ["firefox", "webDriverBiDi"],
"expectations": ["SKIP"] "expectations": ["SKIP"]
}, },
{
"testIdPattern": "[locator.spec] Locator Locator.change should override pre-filled inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for contenteditable",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work for pre-filled inputs",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[locator.spec] Locator Locator.change should work if the input becomes enabled later",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{ {
"testIdPattern": "[mouse.spec] Mouse should reset properly", "testIdPattern": "[mouse.spec] Mouse should reset properly",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],