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: ensure moving focus between frames works (#43456)
Dmitry Gozman57b41cc220fe
diff --git a/tests/library/emulation-focus.spec.ts b/tests/library/emulation-focus.spec.tsindex 63ab7700ad..653fa0e925 100644--- a/tests/library/emulation-focus.spec.ts+++ b/tests/library/emulation-focus.spec.ts@@ -198,8 +198,10 @@ browserTest('should not fire blur events when interacting with more than one pagexpect(await page2.evaluate(() => !!window['gotBlur'])).toBe(false);});-browserTest('should not blur iframe when interacting with another page/context', async ({ contextFactory }) => {+browserTest('should not blur iframe when interacting with another page/context', async ({ contextFactory, browserName }) => {browserTest.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/42933' });+ browserTest.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/43280');+const page1 = await (await contextFactory()).newPage();const page2 = await (await contextFactory()).newPage();const srcdoc = `<button id=foo>foo</button><script>window.addEventListener('blur', () => window.gotBlur = true)</script>`;diff --git a/tests/page/page-focus.spec.ts b/tests/page/page-focus.spec.tsindex ce66a88fce..c6552aeda6 100644--- a/tests/page/page-focus.spec.ts+++ b/tests/page/page-focus.spec.ts@@ -207,3 +207,32 @@ it('keeps focus on element when attempting to focus a non-focusable element', as'focus focusable',]);});++it('should move focus from an iframe to its parent', async ({ page, server }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43280' });+ server.setRoute('/frame.html', (req, res) => {+ res.setHeader('content-type', 'text/html');+ res.end(`<input id=inner>`);+ });+ await page.goto(server.EMPTY_PAGE);+ await page.setContent(`<iframe src="${server.PREFIX}/frame.html"></iframe><input id=outer>`);+ await page.frameLocator('iframe').locator('#inner').focus();+ expect(await page.frameLocator('iframe').locator('#inner').evaluate(e => e === document.activeElement)).toBe(true);+ await page.evaluate(() => (document.getElementById('outer') as HTMLInputElement).focus());+ await expect(page.locator('#outer')).toBeFocused();+ expect(await page.frameLocator('iframe').locator('#inner').evaluate(e => e === document.activeElement)).toBe(false);+});++it('should tab from an iframe to its parent', async ({ page, server }) => {+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43280' });+ server.setRoute('/frame.html', (req, res) => {+ res.setHeader('content-type', 'text/html');+ res.end(`<input id=inner>`);+ });+ await page.goto(server.EMPTY_PAGE);+ await page.setContent(`<iframe src="${server.PREFIX}/frame.html"></iframe><input id=outer>`);+ await page.frameLocator('iframe').locator('#inner').click();+ expect(await page.frameLocator('iframe').locator('#inner').evaluate(e => e === document.activeElement)).toBe(true);+ await page.keyboard.press('Tab');+ await expect(page.locator('#outer')).toBeFocused();+});