|
| 1 | +import { |
| 2 | + _electron as electron, |
| 3 | + test as base, |
| 4 | + type ElectronApplication, |
| 5 | + type Page, |
| 6 | +} from "@playwright/test"; |
| 7 | +import path from "path"; |
| 8 | +import { fileURLToPath } from "url"; |
| 9 | + |
| 10 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 11 | +const ELECTRON_APP_PATH = path.resolve(__dirname, "../../electron-app"); |
| 12 | + |
| 13 | +type ElectronFixtures = { |
| 14 | + app: ElectronApplication; |
| 15 | + page: Page; |
| 16 | + logPage: Page; |
| 17 | +}; |
| 18 | + |
| 19 | +export const test = base.extend<ElectronFixtures>({ |
| 20 | + app: async ({}, use) => { |
| 21 | + const app = await electron.launch({ |
| 22 | + args: [path.join(ELECTRON_APP_PATH, "main.js")], |
| 23 | + cwd: ELECTRON_APP_PATH, |
| 24 | + env: { |
| 25 | + ...process.env, |
| 26 | + NODE_ENV: "test", |
| 27 | + }, |
| 28 | + }); |
| 29 | + |
| 30 | + // Suppress backend error dialogs — binary may not be available in test env |
| 31 | + await app.evaluate(({ dialog }) => { |
| 32 | + dialog.showErrorBox = () => {}; |
| 33 | + }); |
| 34 | + |
| 35 | + // Wait for both windows to open before yielding the app fixture, |
| 36 | + // so logPage and logWindow fixtures can safely index into app.windows() |
| 37 | + await app.firstWindow(); // Backend Logs — always first |
| 38 | + await app.waitForEvent("window"); // Control Station — always second |
| 39 | + |
| 40 | + await use(app); |
| 41 | + await app.close(); |
| 42 | + }, |
| 43 | + |
| 44 | + // Backend logs window — always opens first |
| 45 | + logPage: async ({ app }, use) => { |
| 46 | + const page = app.windows()[0]; |
| 47 | + await page.waitForLoadState("domcontentloaded"); |
| 48 | + await use(page); |
| 49 | + }, |
| 50 | + |
| 51 | + // Main control station window — always opens second |
| 52 | + page: async ({ app }, use) => { |
| 53 | + const page = app.windows()[1]; |
| 54 | + await page.waitForLoadState("domcontentloaded"); |
| 55 | + await use(page); |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +export { expect } from "@playwright/test"; |
0 commit comments