2026-06-06 10:58:23 +08:00
|
|
|
import fs from "node:fs";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { test as setup } from "@playwright/test";
|
|
|
|
|
|
|
|
|
|
const authFile = path.join(process.cwd(), ".playwright", ".auth", "qa-user.json");
|
|
|
|
|
|
|
|
|
|
setup("authenticate for QA", async ({ page }) => {
|
|
|
|
|
const dir = path.dirname(authFile);
|
|
|
|
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
|
|
|
|
|
|
|
|
await page.goto("/login");
|
|
|
|
|
await page.getByLabel("Username").fill("admin");
|
|
|
|
|
await page.getByLabel("Password").fill("admin");
|
|
|
|
|
await page.getByRole("button", { name: /login/i }).click();
|
|
|
|
|
|
2026-06-24 13:30:18 +08:00
|
|
|
// Wait for login to complete (the token lands in localStorage)
|
|
|
|
|
await page.waitForFunction(() => localStorage.getItem("snapotter-token"), null, {
|
2026-06-06 10:58:23 +08:00
|
|
|
timeout: 15_000,
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-24 14:45:37 +08:00
|
|
|
// After login the app redirects to "/" on its own. Wait for that redirect to
|
|
|
|
|
// settle before forcing navigation, otherwise page.goto races the in-flight
|
|
|
|
|
// client-side redirect and aborts ("interrupted by another navigation").
|
2026-06-06 10:58:23 +08:00
|
|
|
await page.waitForURL((url) => url.pathname === "/", { timeout: 15_000 }).catch(() => {});
|
2026-06-24 14:45:37 +08:00
|
|
|
await page.goto("/", { waitUntil: "domcontentloaded" });
|
2026-06-06 10:58:23 +08:00
|
|
|
await page.waitForLoadState("load");
|
|
|
|
|
|
|
|
|
|
await page.context().storageState({ path: authFile });
|
|
|
|
|
});
|