Skip to content

Commit f95684a

Browse files
authored
Revert "feat(keyboard): add array overload to pressSequentially (#40748)" (#41212)
1 parent 123c334 commit f95684a

12 files changed

Lines changed: 14 additions & 190 deletions

File tree

docs/src/api/class-keyboard.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -308,52 +308,35 @@ In most cases, you should use [`method: Locator.fill`] instead. You only need to
308308

309309
Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
310310

311-
When [`option: namedKeys`] is `true`, anything inside `{}` is treated as a key name (same format as [`method: Keyboard.press`]).
312-
313311
To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
314312

315313
**Usage**
316314

317315
```js
318316
await page.keyboard.type('Hello'); // Types instantly
319317
await page.keyboard.type('World', { delay: 100 }); // Types slower, like a user
320-
321-
// Mix text and special keys
322-
await page.keyboard.type('Hello{Enter}World', { namedKeys: true });
323318
```
324319

325320
```java
326321
// Types instantly
327322
page.keyboard().type("Hello");
328323
// Types slower, like a user
329324
page.keyboard().type("World", new Keyboard.TypeOptions().setDelay(100));
330-
331-
// Mix text and special keys
332-
page.keyboard().type("Hello{Enter}World", new Keyboard.TypeOptions().setNamedKeys(true));
333325
```
334326

335327
```python async
336328
await page.keyboard.type("Hello") # types instantly
337329
await page.keyboard.type("World", delay=100) # types slower, like a user
338-
339-
# Mix text and special keys
340-
await page.keyboard.type("Hello{Enter}World", named_keys=True)
341330
```
342331

343332
```python sync
344333
page.keyboard.type("Hello") # types instantly
345334
page.keyboard.type("World", delay=100) # types slower, like a user
346-
347-
# Mix text and special keys
348-
page.keyboard.type("Hello{Enter}World", named_keys=True)
349335
```
350336

351337
```csharp
352338
await page.Keyboard.TypeAsync("Hello"); // types instantly
353339
await page.Keyboard.TypeAsync("World", new() { Delay = 100 }); // types slower, like a user
354-
355-
// Mix text and special keys
356-
await page.Keyboard.TypeAsync("Hello{Enter}World", new() { NamedKeys = true });
357340
```
358341

359342
:::note
@@ -376,13 +359,6 @@ A text to type into a focused element.
376359

377360
Time to wait between key presses in milliseconds. Defaults to 0.
378361

379-
### option: Keyboard.type.namedKeys
380-
* since: v1.61
381-
- `namedKeys` <[boolean]>
382-
383-
When [`option: namedKeys`] is `true`, anything inside `{}` is treated as a key name (same format as [`method: Keyboard.press`]).
384-
Use `{{` to type a literal brace character. Defaults to `false`.
385-
386362
## async method: Keyboard.up
387363
* since: v1.8
388364

docs/src/api/class-locator.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,52 +2103,33 @@ In most cases, you should use [`method: Locator.fill`] instead. You only need to
21032103

21042104
Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
21052105

2106-
When [`option: namedKeys`] is `true`, anything inside `{}` is treated as a key name (same format as [`method: Locator.press`]).
2107-
21082106
To press a special key, like `Control` or `ArrowDown`, use [`method: Locator.press`].
21092107

21102108
**Usage**
21112109

21122110
```js
21132111
await locator.pressSequentially('Hello'); // Types instantly
21142112
await locator.pressSequentially('World', { delay: 100 }); // Types slower, like a user
2115-
2116-
// Mix characters and named keys
2117-
await locator.pressSequentially('Hello{Enter}World', { namedKeys: true });
2118-
// Use modifier combos
2119-
await locator.pressSequentially('{Control+A}{Delete}Hello', { namedKeys: true });
21202113
```
21212114

21222115
```java
21232116
locator.pressSequentially("Hello"); // Types instantly
21242117
locator.pressSequentially("World", new Locator.pressSequentiallyOptions().setDelay(100)); // Types slower, like a user
2125-
2126-
// Mix characters and named keys
2127-
locator.pressSequentially("Hello{Enter}World", new Locator.pressSequentiallyOptions().setNamedKeys(true));
21282118
```
21292119

21302120
```python async
21312121
await locator.press_sequentially("hello") # types instantly
21322122
await locator.press_sequentially("world", delay=100) # types slower, like a user
2133-
2134-
# Mix characters and named keys
2135-
await locator.press_sequentially("Hello{Enter}World", named_keys=True)
21362123
```
21372124

21382125
```python sync
21392126
locator.press_sequentially("hello") # types instantly
21402127
locator.press_sequentially("world", delay=100) # types slower, like a user
2141-
2142-
# Mix characters and named keys
2143-
locator.press_sequentially("Hello{Enter}World", named_keys=True)
21442128
```
21452129

21462130
```csharp
21472131
await locator.PressSequentiallyAsync("Hello"); // Types instantly
21482132
await locator.PressSequentiallyAsync("World", new() { Delay = 100 }); // Types slower, like a user
2149-
2150-
// Mix characters and named keys
2151-
await locator.PressSequentiallyAsync("Hello{Enter}World", new() { NamedKeys = true });
21522133
```
21532134

21542135
An example of typing into a text field and then submitting the form:
@@ -2187,21 +2168,14 @@ await locator.PressAsync("Enter");
21872168
* since: v1.38
21882169
- `text` <[string]>
21892170

2190-
String of characters to sequentially press into a focused element. When [`option: namedKeys`] is `true`, anything inside `{}` is treated as a key name (same format as [`method: Locator.press`]).
2171+
String of characters to sequentially press into a focused element.
21912172

21922173
### option: Locator.pressSequentially.delay
21932174
* since: v1.38
21942175
- `delay` <[float]>
21952176

21962177
Time to wait between key presses in milliseconds. Defaults to 0.
21972178

2198-
### option: Locator.pressSequentially.namedKeys
2199-
* since: v1.61
2200-
- `namedKeys` <[boolean]>
2201-
2202-
When [`option: namedKeys`] is `true`, anything inside `{}` is treated as a key name (same format as [`method: Locator.press`]).
2203-
Use `{{` to type a literal brace character. Defaults to `false`.
2204-
22052179
### option: Locator.pressSequentially.noWaitAfter = %%-input-no-wait-after-removed-%%
22062180
* since: v1.38
22072181

packages/playwright-client/types/types.d.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14731,10 +14731,6 @@ export interface Locator {
1473114731
* Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the
1473214732
* text.
1473314733
*
14734-
* When [`namedKeys`](https://playwright.dev/docs/api/class-locator#locator-press-sequentially-option-named-keys) is
14735-
* `true`, anything inside `{}` is treated as a key name (same format as
14736-
* [locator.press(key[, options])](https://playwright.dev/docs/api/class-locator#locator-press)).
14737-
*
1473814734
* To press a special key, like `Control` or `ArrowDown`, use
1473914735
* [locator.press(key[, options])](https://playwright.dev/docs/api/class-locator#locator-press).
1474014736
*
@@ -14743,11 +14739,6 @@ export interface Locator {
1474314739
* ```js
1474414740
* await locator.pressSequentially('Hello'); // Types instantly
1474514741
* await locator.pressSequentially('World', { delay: 100 }); // Types slower, like a user
14746-
*
14747-
* // Mix characters and named keys
14748-
* await locator.pressSequentially('Hello{Enter}World', { namedKeys: true });
14749-
* // Use modifier combos
14750-
* await locator.pressSequentially('{Control+A}{Delete}Hello', { namedKeys: true });
1475114742
* ```
1475214743
*
1475314744
* An example of typing into a text field and then submitting the form:
@@ -14758,10 +14749,7 @@ export interface Locator {
1475814749
* await locator.press('Enter');
1475914750
* ```
1476014751
*
14761-
* @param text String of characters to sequentially press into a focused element. When
14762-
* [`namedKeys`](https://playwright.dev/docs/api/class-locator#locator-press-sequentially-option-named-keys) is
14763-
* `true`, anything inside `{}` is treated as a key name (same format as
14764-
* [locator.press(key[, options])](https://playwright.dev/docs/api/class-locator#locator-press)).
14752+
* @param text String of characters to sequentially press into a focused element.
1476514753
* @param options
1476614754
*/
1476714755
pressSequentially(text: string, options?: {
@@ -14770,14 +14758,6 @@ export interface Locator {
1477014758
*/
1477114759
delay?: number;
1477214760

14773-
/**
14774-
* When [`namedKeys`](https://playwright.dev/docs/api/class-locator#locator-press-sequentially-option-named-keys) is
14775-
* `true`, anything inside `{}` is treated as a key name (same format as
14776-
* [locator.press(key[, options])](https://playwright.dev/docs/api/class-locator#locator-press)). Use `{{` to type a
14777-
* literal brace character. Defaults to `false`.
14778-
*/
14779-
namedKeys?: boolean;
14780-
1478114761
/**
1478214762
* This option has no effect.
1478314763
* @deprecated This option has no effect.
@@ -19963,10 +19943,6 @@ export interface Keyboard {
1996319943
*
1996419944
* Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
1996519945
*
19966-
* When [`namedKeys`](https://playwright.dev/docs/api/class-keyboard#keyboard-type-option-named-keys) is `true`,
19967-
* anything inside `{}` is treated as a key name (same format as
19968-
* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press)).
19969-
*
1997019946
* To press a special key, like `Control` or `ArrowDown`, use
1997119947
* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press).
1997219948
*
@@ -19975,9 +19951,6 @@ export interface Keyboard {
1997519951
* ```js
1997619952
* await page.keyboard.type('Hello'); // Types instantly
1997719953
* await page.keyboard.type('World', { delay: 100 }); // Types slower, like a user
19978-
*
19979-
* // Mix text and special keys
19980-
* await page.keyboard.type('Hello{Enter}World', { namedKeys: true });
1998119954
* ```
1998219955
*
1998319956
* **NOTE** Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
@@ -19992,14 +19965,6 @@ export interface Keyboard {
1999219965
* Time to wait between key presses in milliseconds. Defaults to 0.
1999319966
*/
1999419967
delay?: number;
19995-
19996-
/**
19997-
* When [`namedKeys`](https://playwright.dev/docs/api/class-keyboard#keyboard-type-option-named-keys) is `true`,
19998-
* anything inside `{}` is treated as a key name (same format as
19999-
* [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboard-press)). Use `{{` to type
20000-
* a literal brace character. Defaults to `false`.
20001-
*/
20002-
namedKeys?: boolean;
2000319968
}): Promise<void>;
2000419969

2000519970
/**

packages/playwright-core/src/protocol/validator.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ scheme.FrameTypeParams = tObject({
16051605
strict: tOptional(tBoolean),
16061606
text: tString,
16071607
delay: tOptional(tFloat),
1608-
namedKeys: tOptional(tBoolean),
16091608
timeout: tFloat,
16101609
});
16111610
scheme.FrameTypeResult = tOptional(tObject({}));
@@ -2491,7 +2490,6 @@ scheme.PageKeyboardInsertTextResult = tOptional(tObject({}));
24912490
scheme.PageKeyboardTypeParams = tObject({
24922491
text: tString,
24932492
delay: tOptional(tFloat),
2494-
namedKeys: tOptional(tBoolean),
24952493
});
24962494
scheme.PageKeyboardTypeResult = tOptional(tObject({}));
24972495
scheme.PageKeyboardPressParams = tObject({

packages/playwright-core/src/server/dom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,13 +774,13 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
774774
return await progress.race(this.evaluateInUtility(([injected, node]) => injected.blurNode(node), {}));
775775
}
776776

777-
async type(progress: Progress, text: string, options: { delay?: number, namedKeys?: boolean } & types.StrictOptions): Promise<void> {
777+
async type(progress: Progress, text: string, options: { delay?: number } & types.StrictOptions): Promise<void> {
778778
await this._markAsTargetElement(progress);
779779
const result = await this._type(progress, text, options);
780780
return assertDone(throwRetargetableDOMError(result));
781781
}
782782

783-
async _type(progress: Progress, text: string, options: { delay?: number, namedKeys?: boolean } & types.StrictOptions): Promise<'error:notconnected' | 'done'> {
783+
async _type(progress: Progress, text: string, options: { delay?: number } & types.StrictOptions): Promise<'error:notconnected' | 'done'> {
784784
progress.log(`elementHandle.type("${text}")`);
785785
await progress.race(this.instrumentation.onBeforeInputAction(this, progress.metadata));
786786
const result = await this._focus(progress, true /* resetSelectionIfNotFocused */);

packages/playwright-core/src/server/frames.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ export class Frame extends SdkObject<FrameEventMap> {
14701470
dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (progress, handle) => handle._drop(progress, inputFileItems, data, options)));
14711471
}
14721472

1473-
async type(progress: Progress, selector: string, text: string, options: { delay?: number, namedKeys?: boolean, noAutoWaiting?: boolean } & types.StrictOptions) {
1473+
async type(progress: Progress, selector: string, text: string, options: { delay?: number, noAutoWaiting?: boolean } & types.StrictOptions) {
14741474
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options, (progress, handle) => handle._type(progress, text, options)));
14751475
}
14761476

packages/playwright-core/src/server/input.ts

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,20 @@ export class Keyboard {
103103
await this._raw.sendText(progress, text);
104104
}
105105

106-
async apiType(progress: Progress, text: string, options?: { delay?: number, namedKeys?: boolean }) {
106+
async apiType(progress: Progress, text: string, options?: { delay?: number }) {
107107
await progress.race(this._page.instrumentation.onBeforeInputAction(this._page, progress.metadata));
108108
await this.type(progress, text, options);
109109
}
110110

111-
async type(progress: Progress, text: string, options?: { delay?: number, namedKeys?: boolean }) {
111+
async type(progress: Progress, text: string, options?: { delay?: number }) {
112112
const delay = (options && options.delay) || undefined;
113-
for (const token of parseNamedKeys(text, !!options?.namedKeys)) {
114-
if (token.type === 'key') {
115-
await this.press(progress, token.value, { delay });
113+
for (const char of text) {
114+
if (usKeyboardLayout.has(char)) {
115+
await this.press(progress, char, { delay });
116116
} else {
117-
if (usKeyboardLayout.has(token.value)) {
118-
await this.press(progress, token.value, { delay });
119-
} else {
120-
if (delay)
121-
await progress.wait(delay);
122-
await this.insertText(progress, token.value);
123-
}
117+
if (delay)
118+
await progress.wait(delay);
119+
await this.insertText(progress, char);
124120
}
125121
}
126122
}
@@ -358,34 +354,6 @@ function buildLayoutClosure(layout: keyboardLayout.KeyboardLayout): Map<string,
358354
return result;
359355
}
360356

361-
function parseNamedKeys(text: string, namedKeys: boolean): Array<{ type: 'key' | 'char', value: string }> {
362-
if (!namedKeys)
363-
return [...text].map(value => ({ type: 'char' as const, value }));
364-
const result: Array<{ type: 'key' | 'char', value: string }> = [];
365-
let i = 0;
366-
while (i < text.length) {
367-
if (text[i] === '{') {
368-
if (i + 1 < text.length && text[i + 1] === '{') {
369-
result.push({ type: 'char', value: '{' });
370-
i += 2;
371-
} else {
372-
const end = text.indexOf('}', i + 1);
373-
if (end === -1) {
374-
result.push({ type: 'char', value: '{' });
375-
i += 1;
376-
} else {
377-
result.push({ type: 'key', value: text.substring(i + 1, end) });
378-
i = end + 1;
379-
}
380-
}
381-
} else {
382-
result.push({ type: 'char', value: text[i] });
383-
i += 1;
384-
}
385-
}
386-
return result;
387-
}
388-
389357
export interface RawTouchscreen {
390358
tap(progress: Progress, x: number, y: number, modifiers: Set<types.KeyboardModifier>): Promise<void>;
391359
}

0 commit comments

Comments
 (0)