Skip to content

Commit ab71b15

Browse files
wenytang-msCopilot
andcommitted
fix: match Delete/Move to Trash in showMessageBox monkey-patch
On Linux CI (headless, no recycle bin), the delete confirmation uses 'Delete' or 'Move to Trash' as button labels, not 'OK'. Expand the regex to match all known confirm labels. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 73a5342 commit ab71b15

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

test/e2e/fixtures/baseTest.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,23 @@ export const test = base.extend<TestFixtures>({
104104
const page = await electronApp.firstWindow();
105105

106106
// Auto-dismiss Electron native dialogs (e.g. redhat.java refactoring
107-
// confirmation "wants to make refactoring changes"). These dialogs are
108-
// outside the renderer DOM and cannot be handled via Playwright Page API.
109-
// Monkey-patch dialog.showMessageBox in the main process to find and
110-
// click the "OK" button by label, falling back to the first button.
107+
// confirmation, delete file confirmation). These dialogs are outside
108+
// the renderer DOM and cannot be handled via Playwright Page API.
109+
// Monkey-patch dialog.showMessageBox to find and click the confirm
110+
// button by label, falling back to the first button.
111111
await electronApp.evaluate(({ dialog }) => {
112-
const origShowMessageBox = dialog.showMessageBox;
112+
const confirmLabels = /^(OK|Delete|Move to Recycle Bin|Move to Trash)$/i;
113113
dialog.showMessageBox = async (_win: any, opts: any) => {
114-
// opts may be the first arg if called without a window
115114
const options = opts || _win;
116115
const buttons: string[] = options?.buttons || [];
117-
// Find "OK" button index; fall back to first button
118-
let idx = buttons.findIndex((b: string) => /^OK$/i.test(b));
116+
let idx = buttons.findIndex((b: string) => confirmLabels.test(b));
119117
if (idx < 0) idx = 0;
120118
return { response: idx, checkboxChecked: true };
121119
};
122120
dialog.showMessageBoxSync = (_win: any, opts: any) => {
123121
const options = opts || _win;
124122
const buttons: string[] = options?.buttons || [];
125-
let idx = buttons.findIndex((b: string) => /^OK$/i.test(b));
123+
let idx = buttons.findIndex((b: string) => confirmLabels.test(b));
126124
if (idx < 0) idx = 0;
127125
return idx;
128126
};

0 commit comments

Comments
 (0)