Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(chromium): reset mouse position upon page reuse (#32944)

Dmitry Gozman6b1d0361cd55
diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts
index c1ff803338..57ebc5fa69 100644
--- a/packages/playwright-core/src/server/chromium/crPage.ts
+++ b/packages/playwright-core/src/server/chromium/crPage.ts
@@ -364,6 +364,8 @@ export class CRPage implements PageDelegate {
}
async resetForReuse(): Promise<void> {
+ // See https://github.com/microsoft/playwright/issues/22432.
+ await this.rawMouse.move(-1, -1, 'none', new Set(), new Set(), true);
}
async pdf(options: channels.PagePdfParams): Promise<Buffer> {
diff --git a/tests/library/browsercontext-reuse.spec.ts b/tests/library/browsercontext-reuse.spec.ts
index 14590a3ae3..30319f0aad 100644
--- a/tests/library/browsercontext-reuse.spec.ts
+++ b/tests/library/browsercontext-reuse.spec.ts
@@ -203,10 +203,10 @@ test('should ignore binding from beforeunload', async ({ reusedContext }) => {
expect(called).toBe(false);
});
-test('should reset mouse position', async ({ reusedContext, browserName, platform }) => {
+test('should reset mouse position', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/22432' },
+}, async ({ reusedContext, browserName, platform }) => {
// Note: this test only reproduces the issue locally when run with --repeat-each=20.
- test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/22432' });
- test.fixme(browserName === 'chromium' && platform !== 'darwin', 'chromium keeps hover on linux/win');
const pageContent = `
<style>
@@ -214,6 +214,7 @@ test('should reset mouse position', async ({ reusedContext, browserName, platfor
div:hover { background: red; }
html, body { margin: 0; padding: 0; }
</style>
+ <div id=filler>one</div>
<div id=one>one</div>
<div id=two>two</div>
`;
@@ -224,7 +225,7 @@ test('should reset mouse position', async ({ reusedContext, browserName, platfor
await expect(page.locator('#one')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
await expect(page.locator('#two')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
- await page.mouse.move(10, 45);
+ await page.mouse.move(10, 75);
await expect(page.locator('#one')).toHaveCSS('background-color', 'rgb(0, 0, 255)');
await expect(page.locator('#two')).toHaveCSS('background-color', 'rgb(255, 0, 0)');