From 2a63c0a7429b36137a10b17341e6866cb5e71fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 23 Oct 2024 16:31:15 -0400 Subject: [PATCH] idk --- .../obsidian-testing-framework/src/index.ts | 20 +++++++++++++++++-- packages/test-project/playwright.config.ts | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) 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")) } },