import { test as setup, expect } from '@playwright/test'; import * as path from 'path'; const authFile = path.join('tests', 'e2e', '.auth', 'user.json'); setup('xác thực', async ({ page }) => { const user = process.env.E2E_USER; const password = process.env.E2E_PASSWORD; const loginPath = process.env.E2E_LOGIN_PATH || '/login'; const postLoginPath = process.env.E2E_POST_LOGIN_PATH || '/dashboard'; if (!user || !password) { throw new Error('E2E_USER và E2E_PASSWORD phải được thiết lập trong .env'); } await page.goto(loginPath); // Cập nhật các locator bên dưới bằng selector thật từ app (dùng automation-testing skill) await page.getByRole('textbox', { name: 'Email' }).fill(user); await page.getByLabel('Mật khẩu').fill(password); await page.getByRole('button', { name: 'Đăng nhập' }).click(); const escaped = postLoginPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); await expect(page).toHaveURL(new RegExp(escaped)); await page.context().storageState({ path: authFile }); });