Files
everything-is-suitable/everything-is-suitable-admin/e2e/uat/uat-001-auth.spec.ts
T
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

63 lines
2.3 KiB
TypeScript

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/);
});
});
});