From eaa98ce53a736e35ceebc7559f9c0f6201a4e238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 28 Feb 2022 22:43:43 +0100 Subject: [PATCH] feat(keyboard): support simple copy-pasting using meta+c/v (#10828) It's a straightforward change to support new, common, keyboard commands Note that I've tested this locally with Chrome on my Mac but it seems that CI doesn't want to pass Chrome tests - it's running on ubuntu though. Does this mean that I should introduce per-platform editing commands? At the moment there is only a single [`macEditingCommands`](https://github.com/microsoft/playwright/blob/0ed33522c572b974905f642408050d007860e33e/packages/playwright-core/src/server/macEditingCommands.ts) file. References https://github.com/microsoft/playwright/issues/12000 Co-authored-by: Andrey Lushnikov --- .../playwright-core/src/server/macEditingCommands.ts | 2 ++ tests/page/page-keyboard.spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/playwright-core/src/server/macEditingCommands.ts b/packages/playwright-core/src/server/macEditingCommands.ts index d7867da029..8f4c496e8a 100644 --- a/packages/playwright-core/src/server/macEditingCommands.ts +++ b/packages/playwright-core/src/server/macEditingCommands.ts @@ -126,4 +126,6 @@ export const macEditingCommands: {[key: string]: string|string[]} = { 'Shift+Meta+ArrowRight': 'moveToRightEndOfLineAndModifySelection:', 'Meta+KeyA': 'selectAll:', + 'Meta+KeyC': 'copy:', + 'Meta+KeyV': 'paste:', }; diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.ts index ed31edb50e..29638647dc 100644 --- a/tests/page/page-keyboard.spec.ts +++ b/tests/page/page-keyboard.spec.ts @@ -464,6 +464,18 @@ it('should dispatch a click event on a button when Enter gets pressed', async ({ expect((await actual.jsonValue()).clicked).toBe(true); }); +it('should support simple copy-pasting', async ({ page, isMac, browserName }) => { + it.fixme(browserName === 'webkit', 'https://github.com/microsoft/playwright/issues/12000'); + const modifier = isMac ? 'Meta' : 'Control'; + await page.setContent(`
123
`); + await page.focus('div'); + await page.keyboard.press(`${modifier}+KeyA`); + await page.keyboard.press(`${modifier}+KeyC`); + await page.keyboard.press(`${modifier}+KeyV`); + await page.keyboard.press(`${modifier}+KeyV`); + expect(await page.evaluate(() => document.querySelector('div').textContent)).toBe('123123'); +}); + async function captureLastKeydown(page) { const lastEvent = await page.evaluateHandle(() => { const lastEvent = {