import { Page, expect } from '@playwright/test'; export async function navigateAndWait( page: Page, route: string, options?: { timeout?: number } ) { const timeout = options?.timeout ?? 15_000; await page.goto(route, { waitUntil: 'networkidle', timeout }); await page.waitForLoadState('domcontentloaded'); // Allow Angular change detection to settle await page.waitForTimeout(500); } export async function assertNoAngularErrors(page: Page) { const errors: string[] = []; page.on('console', (msg) => { if (msg.type() === 'error' && msg.text().includes('NG0')) { errors.push(msg.text()); } }); await page.waitForTimeout(1000); expect(errors, `Angular errors found: ${errors.join(', ')}`).toHaveLength(0); } export async function assertPageHasContent(page: Page) { const bodyText = await page.locator('body').innerText(); expect( bodyText.trim().length, 'Page should have visible text content' ).toBeGreaterThan(10); } export async function getPageHeading( page: Page ): Promise { const h1 = page.locator('h1').first(); if (await h1.isVisible({ timeout: 3000 }).catch(() => false)) { return h1.innerText(); } const h2 = page.locator('h2').first(); if (await h2.isVisible({ timeout: 2000 }).catch(() => false)) { return h2.innerText(); } return null; }