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

66 lines
2.5 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';
test.describe('UAT: 认证功能验收', () => {
test('UAT-AUTH-01: 有效凭据登录成功', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('admin', 'Test@123');
await expect(page).toHaveURL(/.*dashboard/);
});
test('UAT-AUTH-02: 无效密码登录失败', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.loginAndExpectError('admin', 'wrong_password');
await expect(page).toHaveURL(/.*login/);
});
test('UAT-AUTH-03: 空用户名提交被阻止', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.passwordInput.fill('somepassword');
await loginPage.loginButton.click();
await expect(page.locator('.ant-form-item-explain-error').first()).toBeVisible({ timeout: 5000 });
});
test('UAT-AUTH-04: 空密码提交被阻止', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.usernameInput.fill('admin');
await loginPage.loginButton.click();
await expect(page.locator('.ant-form-item-explain-error').first()).toBeVisible({ timeout: 5000 });
});
test('UAT-AUTH-05: 登出后 Token 被清除', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('admin', 'Test@123');
await expect(page).toHaveURL(/.*dashboard/);
const tokenBefore = await page.evaluate(() => localStorage.getItem('token'));
expect(tokenBefore).not.toBeNull();
await loginPage.logout();
const tokenAfter = await page.evaluate(() => localStorage.getItem('token'));
expect(tokenAfter).toBeNull();
});
test('UAT-AUTH-06: 未认证访问受保护路由重定向', async ({ page }) => {
await page.goto('/users');
await page.waitForTimeout(2000);
await expect(page).toHaveURL(/.*login/, { timeout: 10000 });
});
test('UAT-AUTH-07: 登录页面 UI 元素完整性', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await expect(loginPage.usernameInput).toBeVisible();
await expect(loginPage.passwordInput).toBeVisible();
await expect(loginPage.loginButton).toBeVisible();
await expect(page.locator('input[placeholder="用户名"]')).toBeVisible();
await expect(page.locator('input[placeholder="密码"]')).toBeVisible();
});
});