import { test as setup } from '@playwright/test'; /** * 管理员认证 setup。 * * 将认证状态写入独立的 storageState 文件,避免与其他角色或项目共享同一文件 * 导致的并发/覆盖问题。未来如需会员/教练角色,可新增 auth-member.setup.ts、 * auth-coach.setup.ts,并在 playwright.config.ts 中配置对应 project 的 * storageState。 */ const adminAuthFile = 'playwright/.auth/admin.json'; setup('authenticate as admin', async ({ page }) => { await page.goto('/login'); await page.waitForLoadState('networkidle'); await page.locator('input[placeholder*="用户名"]').fill('admin'); await page.locator('input[placeholder*="密码"]').fill('Test@123'); await page.locator('button:has-text("登录")').click(); await page.waitForURL('**/dashboard', { timeout: 30000 }); await page.context().storageState({ path: adminAuthFile }); });