diff --git a/tests/page/page-focus.spec.ts b/tests/page/page-focus.spec.ts
index 744aefec2e..020526380f 100644
--- a/tests/page/page-focus.spec.ts
+++ b/tests/page/page-focus.spec.ts
@@ -117,6 +117,71 @@ it('clicking checkbox should activate it', async ({ page, browserName, headless,
expect(nodeName).toBe('INPUT');
});
+it('tab should cycle between single input and browser', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32339' }
+}, async ({ page, browserName, headless }) => {
+ it.fixme(browserName === 'chromium' && (!headless || !!process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW),
+ 'Chromium in headful mode keeps input focused.');
+ it.fixme(browserName !== 'chromium');
+ await page.setContent(`
+
+ `);
+ expect(await page.evaluate(() => document.activeElement.tagName)).toBe('BODY');
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.id)).toBe('input1');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus']);
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.tagName)).toBe('BODY');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus', 'blur']);
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.id)).toBe('input1');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus', 'blur', 'focus']);
+});
+
+it('tab should cycle between document elements and browser', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32339' }
+}, async ({ page, browserName, headless }) => {
+ it.fixme(browserName === 'chromium' && (!headless || !!process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW),
+ 'Chromium in headful mode keeps last input focused.');
+ it.fixme(browserName !== 'chromium');
+ await page.setContent(`
+
+
+ `);
+ expect(await page.evaluate(() => document.activeElement.tagName)).toBe('BODY');
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.id)).toBe('input1');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus1']);
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.id)).toBe('input2');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus1', 'blur1', 'focus2']);
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.tagName)).toBe('BODY');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus1', 'blur1', 'focus2', 'blur2']);
+ await page.keyboard.press('Tab');
+ expect(await page.evaluate(() => document.activeElement.id)).toBe('input1');
+ expect(await page.evaluate(() => (window as any).focusEvents)).toEqual(['focus1', 'blur1', 'focus2', 'blur2', 'focus1']);
+});
+
it('keeps focus on element when attempting to focus a non-focusable element', async ({ page }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/14254' });