import { test, expect } from '@playwright/test'; import { test as uatTest } from './uat-base'; import { LoginPage } from '../pages/login-page'; import { DashboardPage } from '../pages/dashboard-page'; import { UserManagementPage } from '../pages/user-management-page'; import { testConfig } from '../core/test-config'; uatTest.describe('UAT-001: 用户注册和登录流程', () => { let loginPage: LoginPage; let dashboardPage: DashboardPage; test.beforeEach(async ({ page, uatLogin, uatDashboard }) => { loginPage = uatLogin; dashboardPage = uatDashboard; }); uatTest('UAT-001-01: 用户成功登录系统', async ({ page }) => { await test.step('Given 用户打开登录页面', async () => { await page.goto(testConfig.getBaseURL()); await expect(page).toHaveTitle(/登录/); }); await test.step('When 用户输入有效的用户名和密码', async () => { await loginPage.login('admin', 'admin123'); }); await test.step('Then 用户应成功登录并跳转到仪表盘', async () => { await expect(page).toHaveURL(/.*dashboard/); await expect(page.locator('[data-testid="page-title"]')).toContainText('仪表盘'); }); }); uatTest('UAT-001-02: 用户登录失败 - 错误密码', async ({ page }) => { await test.step('Given 用户打开登录页面', async () => { await page.goto(testConfig.getBaseURL()); }); await test.step('When 用户输入错误的密码', async () => { await loginPage.login('admin', 'wrongpassword'); }); await test.step('Then 系统应显示错误消息', async () => { await expect(page.locator('.ant-message-error')).toBeVisible(); await expect(page.locator('.ant-message-error')).toContainText('用户名或密码错误'); }); }); uatTest('UAT-001-03: 用户登出系统', async ({ page }) => { await test.step('Given 用户已登录系统', async () => { await page.goto(testConfig.getBaseURL()); await loginPage.login('admin', 'admin123'); await expect(page).toHaveURL(/.*dashboard/); }); await test.step('When 用户点击登出按钮', async () => { await page.click('[data-testid="logout-button"]'); }); await test.step('Then 用户应被重定向到登录页面', async () => { await expect(page).toHaveURL(/.*login/); }); }); });