You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
5.6 KiB
190 lines
5.6 KiB
/**
|
|
* 仪表盘 E2E 测试
|
|
* 验证: 统计数据、活动列表、快捷操作
|
|
*/
|
|
|
|
import { TEST_CONFIG } from './config';
|
|
|
|
export const dashboardE2ETests = {
|
|
name: '仪表盘完整 E2E 测试',
|
|
|
|
/**
|
|
* 执行完整的仪表盘测试流程
|
|
*/
|
|
async runFullTest() {
|
|
console.log('\n🧪 开始仪表盘完整 E2E 测试');
|
|
|
|
// 步骤 1: 登录
|
|
await this.login();
|
|
|
|
// 步骤 2: 验证仪表盘数据加载
|
|
await this.verifyDashboardStats();
|
|
|
|
// 步骤 3: 验证最近活动
|
|
await this.verifyRecentActivities();
|
|
|
|
// 步骤 4: 验证快捷操作
|
|
await this.verifyQuickActions();
|
|
|
|
console.log('\n✅ 仪表盘完整 E2E 测试通过!');
|
|
},
|
|
|
|
/**
|
|
* 登录系统
|
|
*/
|
|
async login() {
|
|
console.log('\n📋 步骤 1: 登录系统');
|
|
|
|
await mcp__plugin_playwright_playwright__browser_navigate({
|
|
url: `${TEST_CONFIG.baseURL}/login`,
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_wait_for({ time: 2 });
|
|
|
|
// 填写登录表单
|
|
await mcp__plugin_playwright_playwright__browser_type({
|
|
ref: 'e25',
|
|
text: TEST_CONFIG.testUser.email,
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_type({
|
|
ref: 'e33',
|
|
text: TEST_CONFIG.testUser.password,
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_click({
|
|
element: '登录按钮',
|
|
ref: 'e34',
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_wait_for({ time: 3 });
|
|
|
|
// 验证登录成功
|
|
const snapshot = await mcp__plugin_playwright_playwright__browser_snapshot({});
|
|
if (!snapshot.includes('仪表盘')) {
|
|
throw new Error('登录失败,未显示仪表盘');
|
|
}
|
|
|
|
console.log('✅ 登录成功');
|
|
},
|
|
|
|
/**
|
|
* 验证仪表盘统计数据
|
|
*/
|
|
async verifyDashboardStats() {
|
|
console.log('\n📋 步骤 2: 验证仪表盘统计数据');
|
|
|
|
// 导航到仪表盘
|
|
await mcp__plugin_playwright_playwright__browser_navigate({
|
|
url: `${TEST_CONFIG.baseURL}/dashboard`,
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_wait_for({ time: 3 });
|
|
|
|
const snapshot = await mcp__plugin_playwright_playwright__browser_snapshot({});
|
|
|
|
// 验证统计卡片存在
|
|
const requiredStats = ['总用户数', '活跃用户', '系统负载', '数据库状态'];
|
|
for (const stat of requiredStats) {
|
|
if (!snapshot.includes(stat)) {
|
|
throw new Error(`未找到统计项: ${stat}`);
|
|
}
|
|
}
|
|
|
|
// 验证数据已加载(不是显示 '-')
|
|
const hasRealData = /总用户数[^]*?\d+/.test(snapshot);
|
|
if (!hasRealData) {
|
|
throw new Error('仪表盘数据未正确加载');
|
|
}
|
|
|
|
// 验证数据库状态显示正常
|
|
if (!snapshot.includes('正常') && !snapshot.includes('数据库状态')) {
|
|
throw new Error('数据库状态未显示');
|
|
}
|
|
|
|
console.log('✅ 仪表盘统计数据验证通过');
|
|
console.log(' - 总用户数: 已显示');
|
|
console.log(' - 活跃用户: 已显示');
|
|
console.log(' - 系统负载: 已显示');
|
|
console.log(' - 数据库状态: 已显示');
|
|
},
|
|
|
|
/**
|
|
* 验证最近活动列表
|
|
*/
|
|
async verifyRecentActivities() {
|
|
console.log('\n📋 步骤 3: 验证最近活动列表');
|
|
|
|
const snapshot = await mcp__plugin_playwright_playwright__browser_snapshot({});
|
|
|
|
// 验证活动列表标题
|
|
if (!snapshot.includes('最近活动')) {
|
|
throw new Error('未找到最近活动列表');
|
|
}
|
|
|
|
// 验证活动项格式(应该有用户邮箱、操作、时间)
|
|
// 活动项应该包含 @ 符号(邮箱)
|
|
const hasActivityItems = snapshot.includes('@') &&
|
|
(snapshot.includes('登录系统') || snapshot.includes('更新资料') || snapshot.includes('创建用户'));
|
|
|
|
if (!hasActivityItems) {
|
|
throw new Error('最近活动列表未正确显示活动项');
|
|
}
|
|
|
|
// 验证状态指示器(绿色/红色圆点)
|
|
// 在 snapshot 中可能显示为样式类名
|
|
const hasStatusIndicator = snapshot.includes('success') || snapshot.includes('error') ||
|
|
snapshot.includes('bg-green-500') || snapshot.includes('bg-red-500');
|
|
|
|
if (!hasStatusIndicator) {
|
|
console.log(' ⚠️ 未检测到状态指示器样式');
|
|
}
|
|
|
|
console.log('✅ 最近活动列表验证通过');
|
|
},
|
|
|
|
/**
|
|
* 验证快捷操作按钮
|
|
*/
|
|
async verifyQuickActions() {
|
|
console.log('\n📋 步骤 4: 验证快捷操作');
|
|
|
|
const snapshot = await mcp__plugin_playwright_playwright__browser_snapshot({});
|
|
|
|
// 验证快捷操作标题
|
|
if (!snapshot.includes('快捷操作')) {
|
|
throw new Error('未找到快捷操作区域');
|
|
}
|
|
|
|
// 验证快捷操作按钮
|
|
const requiredActions = ['添加用户', '系统设置', '数据备份', '查看日志'];
|
|
for (const action of requiredActions) {
|
|
if (!snapshot.includes(action)) {
|
|
throw new Error(`未找到快捷操作: ${action}`);
|
|
}
|
|
}
|
|
|
|
// 测试点击"添加用户"快捷操作
|
|
await mcp__plugin_playwright_playwright__browser_click({
|
|
element: '添加用户快捷操作',
|
|
ref: 'e220',
|
|
});
|
|
|
|
await mcp__plugin_playwright_playwright__browser_wait_for({ time: 1 });
|
|
|
|
// 验证是否导航到用户管理页面
|
|
const currentUrl = await mcp__plugin_playwright_playwright__browser_evaluate({
|
|
function: '() => window.location.pathname',
|
|
});
|
|
|
|
if (currentUrl !== '/users') {
|
|
console.log(` ⚠️ 点击添加用户后 URL 为 ${currentUrl},期望 /users`);
|
|
} else {
|
|
console.log(' ✅ 点击添加用户快捷操作成功导航到用户管理页面');
|
|
}
|
|
|
|
console.log('✅ 快捷操作验证通过');
|
|
},
|
|
};
|
|
|
|
export default dashboardE2ETests;
|
|
|