Skip to content

Commit 5705a39

Browse files
wenytang-msCopilot
andcommitted
fix: click menuitem role instead of action-item container
The .action-item div is a presentation container; VS Code only handles click events on the inner <a role='menuitem'> anchor. Use getByRole to find and click the correct element, and wait for menu dismissal to confirm the click registered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d3f9d18 commit 5705a39

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

test/e2e/utils/vscodeOperator.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,19 @@ export default class VscodeOperator {
168168

169169
/**
170170
* Right-clicks an element and selects an item from the context menu.
171-
* Uses text matching to find the menu item.
171+
* Clicks the `<a role="menuitem">` anchor rather than the outer
172+
* `.action-item` container, because VS Code only handles click events
173+
* on the anchor element.
172174
*/
173175
static async selectContextMenuItem(page: Page, target: ReturnType<Page["locator"]>, menuItemLabel: string | RegExp): Promise<void> {
174176
await target.click({ button: "right" });
175177
const menu = page.locator(".monaco-menu-container");
176178
await menu.waitFor({ state: "visible", timeout: 5_000 });
177-
const item = menu.locator(".action-item").filter({ hasText: menuItemLabel });
178-
await item.first().waitFor({ state: "visible", timeout: 5_000 });
179-
await item.first().click();
179+
const menuItem = menu.getByRole("menuitem", { name: menuItemLabel });
180+
await menuItem.first().waitFor({ state: "visible", timeout: 5_000 });
181+
await menuItem.first().click();
182+
// Wait for context menu to close, confirming the click was effective
183+
await menu.waitFor({ state: "hidden", timeout: 5_000 });
180184
await page.waitForTimeout(Timeout.CLICK);
181185
}
182186

0 commit comments

Comments
 (0)