From c6ea7610a6ef9f60cf690fee3c74b00556f7e9ae Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 22 Oct 2024 18:38:39 +0900 Subject: [PATCH 1/4] test: add test --- .../fixtures/user-event/clipboard.test.ts | 48 +++++++++++++++++++ test/browser/specs/runner.test.ts | 1 + 2 files changed, 49 insertions(+) create mode 100644 test/browser/fixtures/user-event/clipboard.test.ts diff --git a/test/browser/fixtures/user-event/clipboard.test.ts b/test/browser/fixtures/user-event/clipboard.test.ts new file mode 100644 index 000000000000..db1aba6b5324 --- /dev/null +++ b/test/browser/fixtures/user-event/clipboard.test.ts @@ -0,0 +1,48 @@ +import { expect, test } from 'vitest'; +import { page, userEvent, server } from '@vitest/browser/context'; + +test('clipboard', async () => { + document.body.innerHTML = ` + + + + `; + + const modifier = server.platform === 'darwin' ? 'Meta' : 'Control'; + const copy = `{${modifier}>}{c}{/${modifier}}` + const cut = `{${modifier}>}{x}{/${modifier}}` + const paste = `{${modifier}>}{v}{/${modifier}}` + + // write first "hello" and copy to clipboard + await userEvent.click(page.getByPlaceholder('first')); + await userEvent.keyboard('hello'); + await userEvent.keyboard(`{selectall}`); + await userEvent.keyboard(copy); + + // paste twice into second + await userEvent.click(page.getByPlaceholder('second')); + await userEvent.keyboard(paste); + await userEvent.keyboard(paste); + + // cut first "hello" + await userEvent.click(page.getByPlaceholder('first')); + await userEvent.keyboard(`{selectall}`); + await userEvent.keyboard(cut); + + // paste it to third + await userEvent.click(page.getByPlaceholder('third')); + await userEvent.keyboard(paste); + + // hellohello + expect([ + (page.getByPlaceholder('first').element() as any).value, + (page.getByPlaceholder('second').element() as any).value, + (page.getByPlaceholder('third').element() as any).value, + ]).toMatchInlineSnapshot(` + [ + "", + "hellohello", + "hello", + ] + `) +}); diff --git a/test/browser/specs/runner.test.ts b/test/browser/specs/runner.test.ts index 0347d9be2d42..596e68d63eb2 100644 --- a/test/browser/specs/runner.test.ts +++ b/test/browser/specs/runner.test.ts @@ -147,6 +147,7 @@ test('user-event', async () => { "cleanup-retry.test.ts": "pass", "cleanup1.test.ts": "pass", "cleanup2.test.ts": "pass", + "clipboard.test.ts": "pass", } `) }) From 30c458fa957e43177849139fbf8ef0b6726571fc Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 22 Oct 2024 18:48:10 +0900 Subject: [PATCH 2/4] test: debug --- test/browser/specs/runner.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/browser/specs/runner.test.ts b/test/browser/specs/runner.test.ts index 596e68d63eb2..c53d64af5356 100644 --- a/test/browser/specs/runner.test.ts +++ b/test/browser/specs/runner.test.ts @@ -139,9 +139,11 @@ error with a stack }) test('user-event', async () => { - const { ctx } = await runBrowserTests({ + const { ctx, stderr } = await runBrowserTests({ root: './fixtures/user-event', }) + onTestFailed(() => console.error(stderr)) + expect(Object.fromEntries(ctx.state.getFiles().map(f => [f.name, f.result.state]))).toMatchInlineSnapshot(` { "cleanup-retry.test.ts": "pass", From 1d477aba59369d8f4a8998a366ecee0ee37f2239 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 22 Oct 2024 19:05:11 +0900 Subject: [PATCH 3/4] test: meta only for playwright/darwin --- test/browser/fixtures/user-event/clipboard.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/browser/fixtures/user-event/clipboard.test.ts b/test/browser/fixtures/user-event/clipboard.test.ts index db1aba6b5324..27975205483f 100644 --- a/test/browser/fixtures/user-event/clipboard.test.ts +++ b/test/browser/fixtures/user-event/clipboard.test.ts @@ -8,10 +8,13 @@ test('clipboard', async () => { `; - const modifier = server.platform === 'darwin' ? 'Meta' : 'Control'; - const copy = `{${modifier}>}{c}{/${modifier}}` - const cut = `{${modifier}>}{x}{/${modifier}}` - const paste = `{${modifier}>}{v}{/${modifier}}` + const modifier = + server.provider === 'playwright' && server.platform === 'darwin' + ? 'Meta' + : 'Control'; + const copy = `{${modifier}>}{c}{/${modifier}}`; + const cut = `{${modifier}>}{x}{/${modifier}}`; + const paste = `{${modifier}>}{v}{/${modifier}}`; // write first "hello" and copy to clipboard await userEvent.click(page.getByPlaceholder('first')); From a298b2544df25b64538088cd4c92c125512856d3 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 22 Oct 2024 19:17:23 +0900 Subject: [PATCH 4/4] test: fix webdriverio --- test/browser/fixtures/user-event/clipboard.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/browser/fixtures/user-event/clipboard.test.ts b/test/browser/fixtures/user-event/clipboard.test.ts index 27975205483f..25180608d24f 100644 --- a/test/browser/fixtures/user-event/clipboard.test.ts +++ b/test/browser/fixtures/user-event/clipboard.test.ts @@ -8,9 +8,15 @@ test('clipboard', async () => { `; + // https://webdriver.io/docs/api/browser/keys/ + // https://playwright.dev/docs/api/class-keyboard const modifier = - server.provider === 'playwright' && server.platform === 'darwin' - ? 'Meta' + server.provider === 'webdriverio' + ? server.platform === 'darwin' + ? 'Command' + : 'Control' + : server.provider === 'playwright' + ? 'ControlOrMeta' : 'Control'; const copy = `{${modifier}>}{c}{/${modifier}}`; const cut = `{${modifier}>}{x}{/${modifier}}`;