Skip to content

Commit 597d75f

Browse files
committed
Stabilize Linux WebDriver menu test
1 parent 61638a2 commit 597d75f

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

e2e-tauri/specs/pet-window.e2e.mjs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('OpenPet Tauri desktop window', () => {
1111
await expect(hitTarget).toBeDisplayed();
1212

1313
await hitTarget.click();
14-
await hitTarget.click({ button: 'right' });
14+
await openContextMenu(hitTarget);
1515

1616
const menu = await $('[role="menu"]');
1717
await expect(menu).toBeDisplayed();
@@ -44,3 +44,33 @@ async function switchToPetWindow() {
4444
},
4545
);
4646
}
47+
48+
async function openContextMenu(hitTarget) {
49+
await hitTarget.click({ button: 'right' });
50+
51+
const menu = await $('[role="menu"]');
52+
if (await menu.isDisplayed().catch(() => false)) {
53+
return;
54+
}
55+
56+
// WebKitGTK under Xvfb can miss WebDriver's synthesized secondary-button
57+
// click even though the native Tauri webview booted successfully. Keep the
58+
// native WebDriver session, but fall back to dispatching the same DOM
59+
// contextmenu event so the test remains focused on OpenPet's menu behavior.
60+
await browser.execute((selector) => {
61+
const target = document.querySelector(selector);
62+
if (!target) throw new Error(`Unable to find ${selector}`);
63+
const rect = target.getBoundingClientRect();
64+
target.dispatchEvent(
65+
new MouseEvent('contextmenu', {
66+
bubbles: true,
67+
cancelable: true,
68+
button: 2,
69+
buttons: 2,
70+
clientX: rect.left + rect.width / 2,
71+
clientY: rect.top + rect.height / 2,
72+
view: window,
73+
}),
74+
);
75+
}, PET_HIT_TARGET);
76+
}

0 commit comments

Comments
 (0)