Files
novalon-manage-system/novalon-manage-web/e2e/journeys/login-dashboard-logout.spec.ts
T
张翔 bd21e2d1f7 test: E2E 测试用例更新与新增
- 更新 Page Object 模型适配新字段名
- 新增 UAT 测试套件与 journey 测试用例
- 优化测试辅助工具与数据工厂
- 更新 playwright 认证状态
2026-05-06 14:17:51 +08:00

82 lines
2.8 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';
import { DashboardPage } from '../pages/DashboardPage';
test.describe('User Journey: 登录 → 仪表盘 → 登出', () => {
test('UJ-01: 管理员完整登录登出流程', async ({ page }) => {
const loginPage = new LoginPage(page);
const dashboardPage = new DashboardPage(page);
await test.step('访问登录页面', async () => {
await loginPage.goto();
await expect(page).toHaveURL(/.*login/);
await expect(loginPage.usernameInput).toBeVisible();
await expect(loginPage.passwordInput).toBeVisible();
await expect(loginPage.loginButton).toBeVisible();
});
await test.step('输入凭据并登录', async () => {
await loginPage.login('admin', 'Test@123');
});
await test.step('验证登录成功跳转到仪表盘', async () => {
await expect(page).toHaveURL(/.*dashboard/);
});
await test.step('验证仪表盘内容加载', async () => {
await expect(page.locator('.ant-statistic').first()).toBeVisible({ timeout: 15000 });
});
await test.step('验证侧边菜单可见', async () => {
await expect(page.locator('.ant-menu')).toBeVisible();
});
await test.step('点击头像下拉菜单', async () => {
await page.locator('.ant-avatar').first().click();
await page.waitForTimeout(500);
await expect(page.locator('.ant-dropdown-menu-item:has-text("退出登录")')).toBeVisible();
});
await test.step('点击退出登录', async () => {
await page.locator('.ant-dropdown-menu-item:has-text("退出登录")').click();
await page.waitForURL(/.*login/, { timeout: 10000 });
});
await test.step('验证已跳转到登录页面', async () => {
await expect(page).toHaveURL(/.*login/);
});
});
test('UJ-01b: 登录失败场景', async ({ page }) => {
const loginPage = new LoginPage(page);
await test.step('访问登录页面', async () => {
await loginPage.goto();
});
await test.step('输入错误密码', async () => {
await loginPage.loginAndExpectError('admin', 'wrongpassword');
});
await test.step('验证错误消息显示', async () => {
const errorMsg = await loginPage.getErrorMessage();
expect(errorMsg).not.toBeNull();
});
await test.step('验证仍在登录页面', async () => {
await expect(page).toHaveURL(/.*login/);
});
});
test('UJ-01c: 未登录访问受保护页面重定向到登录', async ({ page }) => {
await test.step('直接访问仪表盘', async () => {
await page.goto('/dashboard');
await page.waitForTimeout(2000);
});
await test.step('验证被重定向到登录页面', async () => {
await expect(page).toHaveURL(/.*login/, { timeout: 10000 });
});
});
});