Presupuestador_web/e2e/fixtures/auth.ts

19 lines
944 B
TypeScript

import { chromium, type FullConfig } from "@playwright/test";
import { mkdir } from "node:fs/promises";
import { resolve } from "node:path";
export default async function globalSetup(config: FullConfig) {
const email = process.env.E2E_USER_EMAIL;
const password = process.env.E2E_USER_PASSWORD;
if (!email || !password) throw new Error("E2E_USER_EMAIL and E2E_USER_PASSWORD are required");
await mkdir("test-results", { recursive: true });
const browser = await chromium.launch();
const page = await browser.newPage({ baseURL: config.projects[0].use.baseURL as string });
await page.goto("/login");
await page.locator('input[name="email"]').fill(email);
await page.locator('input[name="password"]').fill(password);
await Promise.all([page.waitForURL("**/quotes"), page.locator('button[type="submit"]').click()]);
await page.context().storageState({ path: resolve("test-results/.auth.json") });
await browser.close();
}