626d06327c
New domain `browser` under frontend/functions/ with 6 Playwright helpers: - pw_launch_browser: chromium + context + page bootstrap with storageState support and baseUrl navigation. - pw_kanban_login: authenticates a Page against /api/auth/login; sets the kanban_session cookie via shared storageState; verifies login page no longer visible after navigation. - pw_drag_drop: human-like pointer drag (mousedown + activateOffset + stepped move + mouseup) compatible with @dnd-kit/core's 8px activation threshold; supports hoverMs for time-based dropzones. - pw_keyboard_sequence: ordered focus/type/press/wait steps for scripting realistic input flows (typing then arrow-key navigating autocompletes). - pw_wait_predicate: thin wrapper over page.waitForFunction with friendlier defaults and custom error messages. - pw_assert_class: poll-based assertion that a Locator has/lacks a CSS class within a timeout; useful for visual-state checks. Each function ships with vitest tests (5-8 cases each) covering both happy and error paths, plus self-documenting .md (Ejemplo + Cuando usarla + Gotchas + frontmatter with params/output schema). Adds frontend/functions/package.json with `"type": "module"` so consumers can ESM-import the .ts files from anywhere in the registry (Playwright's tsx loader respects nearest package.json). Capability page docs/capabilities/playwright.md documents the group with a canonical end-to-end example, frontiers, prerequisites, and gotchas. Index updated. First consumer (issue 0088): apps/kanban requester-input.spec.ts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import type { Page } from "playwright";
|
|
|
|
/** Options for authenticating a Playwright Page against the kanban backend. */
|
|
export interface PwLoginOptions {
|
|
username: string;
|
|
password: string;
|
|
/** Base URL of the kanban server. Defaults to the origin of page.url(). */
|
|
baseUrl?: string;
|
|
}
|
|
|
|
/**
|
|
* pw_kanban_login — authenticates a Playwright Page against the kanban backend.
|
|
*
|
|
* Posts credentials to POST /api/auth/login. The request fixture shares storageState
|
|
* with the page context, so the Set-Cookie: kanban_session cookie auto-propagates.
|
|
* After successful login, navigates to root and verifies the login page is gone.
|
|
*
|
|
* Throws if the login response returns HTTP >= 400 or if the login page remains
|
|
* visible after navigation.
|
|
*/
|
|
export async function pw_kanban_login(page: Page, opts: PwLoginOptions): Promise<void> {
|
|
const { username, password } = opts;
|
|
|
|
// Resolve baseUrl from opts or from current page origin
|
|
const baseUrl = opts.baseUrl ?? new URL(page.url()).origin;
|
|
|
|
// POST credentials — page.request shares cookies/storageState with the page context
|
|
const response = await page.request.post(`${baseUrl}/api/auth/login`, {
|
|
data: { username, password },
|
|
});
|
|
|
|
if (response.status() >= 400) {
|
|
throw new Error(`kanban login failed: ${response.status()}`);
|
|
}
|
|
|
|
// Navigate to root; cookie is already propagated via shared context
|
|
await page.goto(`${baseUrl}/`);
|
|
await page.waitForLoadState("networkidle");
|
|
await page.waitForSelector("body", { state: "attached" });
|
|
|
|
// Sanity check: ensure we are no longer on the login page
|
|
const loginTextVisible =
|
|
(await page.locator("text=Login").isVisible()) ||
|
|
(await page.locator("text=Iniciar sesión").isVisible());
|
|
|
|
if (loginTextVisible) {
|
|
throw new Error("kanban login failed: login page still visible after authentication");
|
|
}
|
|
}
|