diff --git a/packages/obsidian-testing-framework/src/index.ts b/packages/obsidian-testing-framework/src/index.ts index 21898a7..11f8b15 100644 --- a/packages/obsidian-testing-framework/src/index.ts +++ b/packages/obsidian-testing-framework/src/index.ts @@ -6,6 +6,7 @@ import { ObsidianTestFixtures } from "./fixtures.js"; import { existsSync } from "fs"; import { getApp, waitForIndexingComplete } from "./util.js"; import {execSync} from "child_process"; +import { Page } from "playwright"; export interface ObsidianTestingConfig { vault?: string; @@ -33,6 +34,18 @@ export function getExe(): string { return "" } +async function selectNewVault(page: Page, vaultPath: string) { + try { + let btn = await page.locator("button", {hasText: "Open"}); + const promise = page.waitForEvent("filechooser"); + await btn.click(); + const chooser = await promise; + await chooser.setFiles(vaultPath); + } catch(e) { + console.debug("congratulations, you don't have to choose a vault manually!") + } +} + const obsidianTestFixtures: Fixtures = { electronApp: [ async ({ obsidian: { vault } }, run) => { @@ -57,10 +70,13 @@ const obsidianTestFixtures: Fixtures = { { timeout: 60000 }, ], page: [ - async ({ electronApp }, run) => { - const page = await electronApp.firstWindow(); + async ({ electronApp, obsidian: {vault} }, run) => { + const windows = electronApp.windows(); + console.log("windows", windows); + const page = windows.last()!; await page.waitForEvent("load") await page.waitForLoadState("domcontentloaded"); + await selectNewVault(page, vault!); await waitForIndexingComplete(await getApp(page)); page.on("console", async (msg) => { console.log( diff --git a/packages/test-project/playwright.config.ts b/packages/test-project/playwright.config.ts index faf16f1..d27b864 100644 --- a/packages/test-project/playwright.config.ts +++ b/packages/test-project/playwright.config.ts @@ -35,7 +35,7 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', obsidian: { - vault: path.resolve(path.join(process.cwd(), "..", "..", "vault", "test-framework-tester")) + vault: path.resolve(process.cwd(), "..", "..", path.join("vault", "test-framework-tester")) } },