33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
|
|
// Real-UI login once, save storage state for all tests (per worker contexts will load it).
|
|
// Uses existing test user loader and the same selectors your signin spec uses.
|
|
import { chromium } from '@playwright/test';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { loadTestUser } from '../utils/testUser.js';
|
|
|
|
const STATE_PATH = '/home/jcoakley/aptiva-dev1-app/tests/.auth/state.json';
|
|
|
|
export default async () => {
|
|
const user = loadTestUser();
|
|
const baseURL = process.env.PW_BASE_URL || 'http://localhost:3000';
|
|
|
|
// Ensure target dir exists
|
|
fs.mkdirSync(path.dirname(STATE_PATH), { recursive: true });
|
|
|
|
const browser = await chromium.launch();
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
|
|
// Real UI flow (selectors match your 02-signin-landing.spec.mjs)
|
|
await page.goto(new URL('/signin', baseURL).toString(), { waitUntil: 'networkidle' });
|
|
await page.getByPlaceholder('Username', { exact: true }).fill(user.username);
|
|
await page.getByPlaceholder('Password', { exact: true }).fill(user.password);
|
|
await page.getByRole('button', { name: /^Sign In$/ }).click();
|
|
await page.waitForURL('**/signin-landing**', { timeout: 30000 });
|
|
|
|
// Persist authenticated cookies/localStorage
|
|
await context.storageState({ path: STATE_PATH });
|
|
await browser.close();
|
|
};
|