import { test as base, expect, type BrowserContext } from '@playwright/test'; import { installGuard } from './network'; type State = Awaited>; export const test = base.extend<{ guard: Awaited> }, { signedIn: State }>({ signedIn: [async ({ browser }, use) => { const username = process.env.VOTIAN_UI_USERNAME; const password = process.env.VOTIAN_UI_PASSWORD; if (!username || !password) throw new Error('Votian UI credentials required. Run python3 legacy-ui-tests/run.py.'); const context = await browser.newContext({ locale: 'de-DE', serviceWorkers: 'block' }); const guard = await installGuard(context, true); try { const page = await context.newPage(); await page.goto('https://test.sb.assecutor.de/admin/login.php'); const details = page.locator('details').filter({ has: page.locator('input[name="f_chk_account"]') }); if (await details.count() && !(await details.getAttribute('open'))) await details.locator('summary').click(); await page.locator('input[name="f_chk_account"]').fill(username); await page.locator('input[name="f_chk_password"]').fill(password); await page.locator('[name="f_submit"]').click(); await expect(page).toHaveURL(/\/admin\/start\.php/); expect(guard.errors, 'Legacy JavaScript errors').toEqual([]); expect(guard.denied, 'Unexpected requests during login').toEqual([]); const state = await context.storageState(); await use(state); } finally { await context.close(); } }, { scope: 'worker' }], storageState: async ({ signedIn }, use) => { await use(signedIn); }, guard: [async ({ context }, use, info) => { const guard = await installGuard(context); await use(guard); if (info.status !== info.expectedStatus) await info.attach('request-paths', { body: JSON.stringify([...new Set(guard.allowed)], null, 2), contentType: 'application/json' }); if (guard.consoleErrors.length) await info.attach('console-diagnostics', { body: JSON.stringify(guard.consoleErrors, null, 2), contentType: 'application/json' }); if (guard.knownErrors.length) await info.attach('known-opener-bug', { body: JSON.stringify(guard.knownErrors), contentType: 'application/json' }); if (guard.errors.length) await info.attach('legacy-js-errors', { body: JSON.stringify(guard.errors), contentType: 'application/json' }); if (guard.denied.length) { await info.attach('blocked-request-paths', { body: JSON.stringify([...new Set(guard.denied)], null, 2), contentType: 'application/json' }); } expect(guard.errors, 'Legacy JavaScript errors').toEqual([]); expect(guard.denied, 'Unexpected request (blocked before it reached the server)').toEqual([]); }, { auto: true }], }); export { expect } from '@playwright/test';