Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/src/electron-api/class-electron.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ If you are not able to launch Electron and it will end up in timeouts during lau

* Ensure that `nodeCliInspect` ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect)) fuse is **not** set to `false`.

**Mocking native dialogs:**

Playwright does not intercept the native Electron [dialog](https://www.electronjs.org/docs/latest/api/dialog) API
(`dialog.showOpenDialog`, `dialog.showSaveDialog`, `dialog.showMessageBox`, etc.) because those calls happen in the
Electron main process and go straight to OS APIs. Use [`method: ElectronApplication.evaluate`] to replace the
relevant methods in the main process so tests run deterministically without any OS-level UI:

```js
// Stub the open dialog to always return a fixed path.
await electronApp.evaluate(({ dialog }, filePaths) => {
dialog.showOpenDialog = () => Promise.resolve({ canceled: false, filePaths });
}, ['/path/to/file.txt']);

// Stub the save dialog.
await electronApp.evaluate(({ dialog }, filePath) => {
dialog.showSaveDialog = () => Promise.resolve({ canceled: false, filePath });
}, '/path/to/saved.txt');

// Stub showMessageBox to click the first button.
await electronApp.evaluate(({ dialog }) => {
dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
});
```

The replacement persists until the application is closed. Synchronous variants
(`showOpenDialogSync`, `showSaveDialogSync`, `showMessageBoxSync`) can be stubbed the same way — just return the
value directly instead of a `Promise`.

## async method: Electron.launch
* since: v1.9
- returns: <[ElectronApplication]>
Expand Down
29 changes: 29 additions & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22195,6 +22195,35 @@ export interface WebStorage {
* - Ensure that `nodeCliInspect`
* ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect))
* fuse is **not** set to `false`.
*
* **Mocking native dialogs:**
*
* Playwright does not intercept the native Electron [dialog](https://www.electronjs.org/docs/latest/api/dialog) API
* (`dialog.showOpenDialog`, `dialog.showSaveDialog`, `dialog.showMessageBox`, etc.) because those calls happen in the
* Electron main process and go straight to OS APIs. Use
* [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
* to replace the relevant methods in the main process so tests run deterministically without any OS-level UI:
*
* ```js
* // Stub the open dialog to always return a fixed path.
* await electronApp.evaluate(({ dialog }, filePaths) => {
* dialog.showOpenDialog = () => Promise.resolve({ canceled: false, filePaths });
* }, ['/path/to/file.txt']);
*
* // Stub the save dialog.
* await electronApp.evaluate(({ dialog }, filePath) => {
* dialog.showSaveDialog = () => Promise.resolve({ canceled: false, filePath });
* }, '/path/to/saved.txt');
*
* // Stub showMessageBox to click the first button.
* await electronApp.evaluate(({ dialog }) => {
* dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
* });
* ```
*
* The replacement persists until the application is closed. Synchronous variants (`showOpenDialogSync`,
* `showSaveDialogSync`, `showMessageBoxSync`) can be stubbed the same way — just return the value directly instead of
* a `Promise`.
*/
export interface Electron {
/**
Expand Down
29 changes: 29 additions & 0 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22195,6 +22195,35 @@ export interface WebStorage {
* - Ensure that `nodeCliInspect`
* ([FuseV1Options.EnableNodeCliInspectArguments](https://www.electronjs.org/docs/latest/tutorial/fuses#nodecliinspect))
* fuse is **not** set to `false`.
*
* **Mocking native dialogs:**
*
* Playwright does not intercept the native Electron [dialog](https://www.electronjs.org/docs/latest/api/dialog) API
* (`dialog.showOpenDialog`, `dialog.showSaveDialog`, `dialog.showMessageBox`, etc.) because those calls happen in the
* Electron main process and go straight to OS APIs. Use
* [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electron-application-evaluate)
* to replace the relevant methods in the main process so tests run deterministically without any OS-level UI:
*
* ```js
* // Stub the open dialog to always return a fixed path.
* await electronApp.evaluate(({ dialog }, filePaths) => {
* dialog.showOpenDialog = () => Promise.resolve({ canceled: false, filePaths });
* }, ['/path/to/file.txt']);
*
* // Stub the save dialog.
* await electronApp.evaluate(({ dialog }, filePath) => {
* dialog.showSaveDialog = () => Promise.resolve({ canceled: false, filePath });
* }, '/path/to/saved.txt');
*
* // Stub showMessageBox to click the first button.
* await electronApp.evaluate(({ dialog }) => {
* dialog.showMessageBox = () => Promise.resolve({ response: 0, checkboxChecked: false });
* });
* ```
*
* The replacement persists until the application is closed. Synchronous variants (`showOpenDialogSync`,
* `showSaveDialogSync`, `showMessageBoxSync`) can be stubbed the same way — just return the value directly instead of
* a `Promise`.
*/
export interface Electron {
/**
Expand Down
Loading