Created
October 29, 2021 14:24
-
-
Save el3um4s/9bc6fc06d8726ea9aabb7f570e0332b9 to your computer and use it in GitHub Desktop.
MEDIUM - Ho to Test Electron Apps - 06
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { _electron as electron } from "playwright"; | |
import { test, expect } from "@playwright/test"; | |
test("Launch electron app", async () => { | |
const electronApp = await electron.launch({ args: ["."] }); | |
const windowState: { | |
isVisible: boolean; | |
isDevToolsOpened: boolean; | |
isCrashed: boolean; | |
} = await electronApp.evaluate(async ({ BrowserWindow }) => { | |
const mainWindow = BrowserWindow.getAllWindows()[0]; | |
const getState = () => ({ | |
isVisible: mainWindow.isVisible(), | |
isDevToolsOpened: mainWindow.webContents.isDevToolsOpened(), | |
isCrashed: mainWindow.webContents.isCrashed(), | |
}); | |
return new Promise((resolve) => { | |
if (mainWindow.isVisible()) { | |
resolve(getState()); | |
} else { | |
mainWindow.once("ready-to-show", () => | |
setTimeout(() => resolve(getState()), 0) | |
); | |
} | |
}); | |
}); | |
expect(windowState.isVisible).toBeTruthy(); | |
expect(windowState.isDevToolsOpened).toBeFalsy(); | |
expect(windowState.isCrashed).toBeFalsy(); | |
await electronApp.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment