Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(keyboard): fix NumpadDecimal key and Shift+numpad digits in Chromium (#42927)

Yuriy Mikityuka20b6148ec87
diff --git a/packages/playwright-core/src/server/input.ts b/packages/playwright-core/src/server/input.ts
index a31ed8684f..2a30b05e48 100644
--- a/packages/playwright-core/src/server/input.ts
+++ b/packages/playwright-core/src/server/input.ts
@@ -326,8 +326,10 @@ function buildLayoutClosure(layout: keyboardLayout.KeyboardLayout): Map<string,
shiftedDescription = { ...description };
shiftedDescription.key = definition.shiftKey;
shiftedDescription.text = definition.shiftKey;
- if (definition.shiftKeyCode)
+ if (definition.shiftKeyCode) {
shiftedDescription.keyCode = definition.shiftKeyCode;
+ shiftedDescription.keyCodeWithoutLocation = definition.shiftKeyCode;
+ }
}
// Map from code: Digit3 -> { ... description, shifted }
diff --git a/packages/playwright-core/src/server/usKeyboardLayout.ts b/packages/playwright-core/src/server/usKeyboardLayout.ts
index 5bf92ffe17..fbbfbaab46 100644
--- a/packages/playwright-core/src/server/usKeyboardLayout.ts
+++ b/packages/playwright-core/src/server/usKeyboardLayout.ts
@@ -158,6 +158,6 @@ export const USKeyboardLayout: KeyboardLayout = {
'Numpad2': { 'keyCode': 40, 'shiftKeyCode': 98, 'key': 'ArrowDown', 'shiftKey': '2', 'location': 3 },
'Numpad3': { 'keyCode': 34, 'shiftKeyCode': 99, 'key': 'PageDown', 'shiftKey': '3', 'location': 3 },
'Numpad0': { 'keyCode': 45, 'shiftKeyCode': 96, 'key': 'Insert', 'shiftKey': '0', 'location': 3 },
- 'NumpadDecimal': { 'keyCode': 46, 'shiftKeyCode': 110, 'key': '\u0000', 'shiftKey': '.', 'location': 3 },
+ 'NumpadDecimal': { 'keyCode': 46, 'shiftKeyCode': 110, 'key': 'Delete', 'shiftKey': '.', 'location': 3 },
'NumpadEnter': { 'keyCode': 13, 'key': 'Enter', 'text': '\r', 'location': 3 },
};
diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts
index 42125f4968..d79ba409d3 100644
--- a/tests/page/page-keyboard.spec.ts
+++ b/tests/page/page-keyboard.spec.ts
@@ -331,6 +331,27 @@ it('should specify numpad location on keyup', async ({ page, server }) => {
'Keyup: - NumpadSubtract NUMPAD []'].join('\n'));
});
+it('should press NumpadDecimal as Delete', async ({ page }) => {
+ await page.setContent('<textarea></textarea>');
+ const lastEvent = await captureLastKeydown(page);
+ const textarea = page.locator('textarea');
+
+ await textarea.press('NumpadDecimal');
+ expect(await lastEvent.evaluate(e => e.key)).toBe('Delete');
+ expect(await lastEvent.evaluate(e => e.code)).toBe('NumpadDecimal');
+ expect(await lastEvent.evaluate(e => e.location)).toBe(3);
+ await expect(textarea).toHaveValue('');
+});
+
+it('should type numpad digits with Shift', async ({ page }) => {
+ await page.setContent('<textarea></textarea>');
+ const textarea = page.locator('textarea');
+ await textarea.press('Shift+Numpad1');
+ await textarea.press('Shift+NumpadDecimal');
+ await textarea.press('Shift+Numpad9');
+ await expect(textarea).toHaveValue('1.9');
+});
+
it('should press Enter', async ({ page, server }) => {
await page.setContent('<textarea></textarea>');
await page.focus('textarea');