Skip to content

Commit bae57aa

Browse files
wenytang-msCopilot
andcommitted
fix: use keyboard shortcuts instead of context menu clicks
Playwright's click() does not reliably trigger actions on VS Code Electron context menu items (the menu stays open). Switch to: 1. Right-click to select tree item and set focusedView 2. Escape to close context menu (returns focus to tree) 3. F2/Delete keyboard shortcut to trigger rename/delete commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5705a39 commit bae57aa

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

test/e2e/tests/fileOperations.test.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,18 @@ test.describe("File Operations", () => {
6969
// Expand to AppToRename
7070
await JavaOperator.expandTreePath(page, "my-app", "src/main/java", "com.mycompany.app");
7171

72-
// Right-click AppToRename and select "Rename" from context menu.
73-
// The command java.view.package.renameFile is hidden from the command
74-
// palette (when: false), so context menu is the only UI path.
72+
// Right-click to select item AND set focusedView = javaProjectExplorer.
73+
// Playwright's click() on VS Code Electron context menu items does not
74+
// reliably trigger actions, so we use the keyboard shortcut instead.
7575
const appToRename = page.getByRole(VSCode.TREE_ITEM_ROLE, { name: "AppToRename" }).first();
76-
await appToRename.click();
76+
await appToRename.click({ button: "right" });
77+
await page.waitForTimeout(Timeout.CLICK);
78+
// Close context menu – focus returns to the tree with item selected
79+
await page.keyboard.press(VSCode.ESCAPE);
80+
await page.waitForTimeout(Timeout.CLICK);
81+
// F2 triggers java.view.package.renameFile (keybinding)
82+
await page.keyboard.press("F2");
7783
await page.waitForTimeout(Timeout.CLICK);
78-
79-
await VscodeOperator.selectContextMenuItem(page, appToRename, "Rename");
8084

8185
// The extension shows a showInputBox (quick-input) for the new name
8286
await VscodeOperator.fillQuickInput(page, "AppRenamed");
@@ -97,14 +101,16 @@ test.describe("File Operations", () => {
97101
await JavaOperator.collapseFileExplorer(page);
98102
await JavaOperator.expandTreePath(page, "my-app", "src/main/java", "com.mycompany.app");
99103

100-
// Right-click AppToDelete and select "Delete" from context menu.
101-
// The command java.view.package.moveFileToTrash is hidden from the
102-
// command palette (when: false), so context menu is the only UI path.
104+
// Right-click to select item AND set focusedView = javaProjectExplorer.
103105
const appToDelete = page.getByRole(VSCode.TREE_ITEM_ROLE, { name: "AppToDelete" }).first();
104-
await appToDelete.click();
106+
await appToDelete.click({ button: "right" });
107+
await page.waitForTimeout(Timeout.CLICK);
108+
// Close context menu – focus returns to the tree with item selected
109+
await page.keyboard.press(VSCode.ESCAPE);
110+
await page.waitForTimeout(Timeout.CLICK);
111+
// Delete key triggers java.view.package.moveFileToTrash (keybinding)
112+
await page.keyboard.press("Delete");
105113
await page.waitForTimeout(Timeout.CLICK);
106-
107-
await VscodeOperator.selectContextMenuItem(page, appToDelete, /^Delete/);
108114

109115
// Confirm deletion in dialog
110116
try {

0 commit comments

Comments
 (0)