Skip to content

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

test: contextmenu on right click (#26885)

Yury Semikhatskyf045e13e00ac
diff --git a/tests/page/page-click.spec.ts b/tests/page/page-click.spec.ts
index c05cb2d00c..2c8a32b40d 100644
--- a/tests/page/page-click.spec.ts
+++ b/tests/page/page-click.spec.ts
@@ -1118,3 +1118,26 @@ it('should click if opened select covers the button', async ({ page }) => {
await page.click('button');
expect(await page.evaluate('window.__CLICKED')).toBe(42);
});
+
+it('should fire contextmenu event on right click in correct order', async ({ page, server, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/26515' });
+ it.fixme(browserName === 'chromium', 'mouseup is fired');
+ it.fixme(browserName === 'firefox', 'mouseup is fired');
+ await page.goto(server.EMPTY_PAGE);
+ await page.setContent(`
+ <button id="target">Click me</button>
+ `);
+ await page.evaluate(() => {
+ const logEvent = e => console.log(e.type);
+ document.addEventListener('mousedown', logEvent);
+ document.addEventListener('mouseup', logEvent);
+ document.addEventListener('contextmenu', logEvent);
+ });
+ const entries = [];
+ page.on('console', message => entries.push(message.text()));
+ await page.getByRole('button', { name: 'Click me' }).click({ button: 'right' });
+ await expect.poll(() => entries).toEqual([
+ 'mousedown',
+ 'contextmenu',
+ ]);
+});