Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(keyboard): add tests for click events being dispatched when Space/Enter gets pressed while focus is on a button (#10748)
Mateusz Burzyński55fb53ef8290
diff --git a/tests/page/page-keyboard.spec.ts b/tests/page/page-keyboard.spec.tsindex 8194cd8418..2edf443976 100644--- a/tests/page/page-keyboard.spec.ts+++ b/tests/page/page-keyboard.spec.ts@@ -440,6 +440,30 @@ it('should move to the start of the document', async ({ page, isMac }) => {expect(await page.evaluate(() => window.getSelection().toString())).toBe('1\n2\n3\n');});+it('should dispatch a click event on a button when Space gets pressed', async ({ page }) => {+ await page.setContent(`<button type="button">a11y</button>`);+ const actual = await page.evaluateHandle(() => {+ const actual = { clicked: false };+ document.querySelector('button').addEventListener('click', () => (actual.clicked = true));+ return actual;+ });+ await page.focus('button');+ await page.keyboard.press('Space');+ expect((await actual.jsonValue()).clicked).toBe(true);+});++it('should dispatch a click event on a button when Enter gets pressed', async ({ page }) => {+ await page.setContent(`<button type="button">a11y</button>`);+ const actual = await page.evaluateHandle(() => {+ const actual = { clicked: false };+ document.querySelector('button').addEventListener('click', () => (actual.clicked = true));+ return actual;+ });+ await page.focus('button');+ await page.keyboard.press('Enter');+ expect((await actual.jsonValue()).clicked).toBe(true);+});+async function captureLastKeydown(page) {const lastEvent = await page.evaluateHandle(() => {const lastEvent = {