diff --git a/tests/page/page-screenshot.spec.ts b/tests/page/page-screenshot.spec.ts index 1103f5d317..b81d6d4165 100644 --- a/tests/page/page-screenshot.spec.ts +++ b/tests/page/page-screenshot.spec.ts @@ -89,6 +89,51 @@ it.describe('page screenshot', () => { expect(hasDifferentScreenshots).toBe(true); }); + it('should capture blinking caret in shadow dom', async ({ page, browserName }) => { + it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16732' }); + it.fixme(browserName !== 'firefox'); + await page.addScriptTag({ + content: ` + class CustomElementContainer extends HTMLElement { + #shadowRoot; + constructor() { + super(); + this.#shadowRoot = this.attachShadow({ mode: 'open' }); + this.#shadowRoot.innerHTML = ''; + } + } + class CustomElementInputWrapper extends HTMLElement { + #shadowRoot; + constructor() { + super(); + this.#shadowRoot = this.attachShadow({ mode: 'open' }); + this.#shadowRoot.innerHTML = ''; + } + } + customElements.define('custom-element-input-wrapper', CustomElementInputWrapper); + customElements.define('custom-element-container', CustomElementContainer); + + const container = document.createElement('custom-element-container'); + document.body.appendChild(container);`, + }); + + const input = await page.locator('input'); + // TODO: click fails in webkit + await input.focus(); + + const screenshot = await input.screenshot(); + let hasDifferentScreenshots = false; + for (let i = 0; !hasDifferentScreenshots && i < 10; ++i) { + // Caret blinking time is set to 500ms. + // Try to capture variety of screenshots to make + // sure we capture blinking caret. + await new Promise(x => setTimeout(x, 150)); + const newScreenshot = await input.screenshot({ caret: 'hide' }); + hasDifferentScreenshots = !newScreenshot.equals(screenshot); + } + expect(hasDifferentScreenshots).toBe(false); + }); + it('should clip rect', async ({ page, server }) => { await page.setViewportSize({ width: 500, height: 500 }); await page.goto(server.PREFIX + '/grid.html');