From 6fb6282a9d946645f3c2989f21e24095be32771f Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 7 Jan 2025 16:46:44 -0800 Subject: [PATCH] chore(bidi): propertly dispatch ControlRight key event (#34246) --- .../playwright-core/src/server/bidi/bidiInput.ts | 2 +- tests/page/page-keyboard.spec.ts | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/playwright-core/src/server/bidi/bidiInput.ts b/packages/playwright-core/src/server/bidi/bidiInput.ts index 3550051a6a71f..5266fef023c73 100644 --- a/packages/playwright-core/src/server/bidi/bidiInput.ts +++ b/packages/playwright-core/src/server/bidi/bidiInput.ts @@ -33,7 +33,7 @@ export class RawKeyboardImpl implements input.RawKeyboard { async keydown(modifiers: Set, code: string, keyCode: number, keyCodeWithoutLocation: number, key: string, location: number, autoRepeat: boolean, text: string | undefined): Promise { const actions: bidi.Input.KeySourceAction[] = []; - actions.push({ type: 'keyDown', value: getBidiKeyValue(key) }); + actions.push({ type: 'keyDown', value: getBidiKeyValue(code) }); // TODO: add modifiers? await this._performActions(actions); } diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts index 027648f48e7a3..0d922584f43e1 100644 --- a/tests/page/page-keyboard.spec.ts +++ b/tests/page/page-keyboard.spec.ts @@ -256,16 +256,24 @@ it('should specify location', async ({ page, server }) => { const textarea = await page.$('textarea'); await textarea.press('Digit5'); - expect(await lastEvent.evaluate(e => e.location)).toBe(0); + expect.soft(await lastEvent.evaluate(e => e.location)).toBe(0); + expect.soft(await lastEvent.evaluate(e => e.key)).toBe('5'); + expect.soft(await lastEvent.evaluate(e => e.code)).toBe('Digit5'); await textarea.press('ControlLeft'); - expect(await lastEvent.evaluate(e => e.location)).toBe(1); + expect.soft(await lastEvent.evaluate(e => e.location)).toBe(1); + expect.soft(await lastEvent.evaluate(e => e.key)).toBe('Control'); + expect.soft(await lastEvent.evaluate(e => e.code)).toBe('ControlLeft'); await textarea.press('ControlRight'); - expect(await lastEvent.evaluate(e => e.location)).toBe(2); + expect.soft(await lastEvent.evaluate(e => e.location)).toBe(2); + expect.soft(await lastEvent.evaluate(e => e.key)).toBe('Control'); + expect.soft(await lastEvent.evaluate(e => e.code)).toBe('ControlRight'); await textarea.press('NumpadSubtract'); - expect(await lastEvent.evaluate(e => e.location)).toBe(3); + expect.soft(await lastEvent.evaluate(e => e.location)).toBe(3); + expect.soft(await lastEvent.evaluate(e => e.key)).toBe('-'); + expect.soft(await lastEvent.evaluate(e => e.code)).toBe('NumpadSubtract'); }); it('should press Enter', async ({ page, server }) => {