977e283fbd
问题分析: 1. 错误消息使用ElMessage toast,测试期望页面文本 2. 登出下拉菜单选择器不够精确 3. 用户管理页面按钮文本不匹配 4. 缺少适当的等待策略 修复内容: - 登录流程测试:检测.el-message--error toast消息 - 表单验证测试:触发blur事件后检测.el-form-item__error - 登出流程测试:使用更精确的下拉菜单选择器 - 用户管理测试:修正按钮文本为'新增用户' - 添加waitForLoadState确保页面加载完成 - 增加timeout参数提高测试稳定性
79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { RoleFactory } from '../../roles/role-factory';
|
|
import { createAuthenticatedPage } from '../../shared/auth-helper';
|
|
|
|
test.describe('登录流程测试', () => {
|
|
test('管理员用户登录成功', async ({ page, context }) => {
|
|
const role = RoleFactory.getRole('admin');
|
|
|
|
await page.goto('/login');
|
|
|
|
await page.fill('input[placeholder*="用户名"]', role.credentials.username);
|
|
await page.fill('input[placeholder*="密码"]', role.credentials.password);
|
|
await page.click('button:has-text("登录")');
|
|
|
|
await expect(page).toHaveURL(/\/(dashboard|\/)?/, { timeout: 10000 });
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
|
|
test('普通用户登录成功', async ({ page, context }) => {
|
|
const role = RoleFactory.getRole('user');
|
|
|
|
await page.goto('/login');
|
|
|
|
await page.fill('input[placeholder*="用户名"]', role.credentials.username);
|
|
await page.fill('input[placeholder*="密码"]', role.credentials.password);
|
|
await page.click('button:has-text("登录")');
|
|
|
|
await expect(page).toHaveURL(/\/(dashboard|\/)?/, { timeout: 10000 });
|
|
});
|
|
|
|
test('错误密码登录失败', async ({ page }) => {
|
|
await page.goto('/login');
|
|
|
|
await page.fill('input[placeholder*="用户名"]', 'admin');
|
|
await page.fill('input[placeholder*="密码"]', 'wrongpassword');
|
|
await page.click('button:has-text("登录")');
|
|
|
|
const errorMessage = page.locator('.el-message--error');
|
|
await expect(errorMessage).toBeVisible({ timeout: 5000 });
|
|
|
|
await expect(page).toHaveURL(/\/login/);
|
|
});
|
|
|
|
test('空用户名登录失败', async ({ page }) => {
|
|
await page.goto('/login');
|
|
|
|
await page.fill('input[placeholder*="密码"]', 'Test@123');
|
|
await page.click('input[placeholder*="用户名"]');
|
|
await page.click('input[placeholder*="密码"]');
|
|
await page.click('button:has-text("登录")');
|
|
|
|
const validationMessage = page.locator('.el-form-item__error');
|
|
await expect(validationMessage).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
test('空密码登录失败', async ({ page }) => {
|
|
await page.goto('/login');
|
|
|
|
await page.fill('input[placeholder*="用户名"]', 'admin');
|
|
await page.click('input[placeholder*="密码"]');
|
|
await page.click('input[placeholder*="用户名"]');
|
|
await page.click('button:has-text("登录")');
|
|
|
|
const validationMessage = page.locator('.el-form-item__error');
|
|
await expect(validationMessage).toBeVisible({ timeout: 5000 });
|
|
});
|
|
|
|
test('Token注入登录', async ({ page, context }) => {
|
|
await createAuthenticatedPage(page, context, 'admin');
|
|
|
|
await page.goto('/dashboard');
|
|
|
|
await expect(page).toHaveURL(/\/dashboard/);
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
});
|
|
});
|