be5d5ede90
refactor: 重构后端查询逻辑和API响应处理 fix: 修复用户角色更新和文件上传问题 test: 添加前端性能测试脚本和E2E测试用例 chore: 更新依赖版本和配置文件 docs: 添加环境检查脚本和测试文档 style: 统一表格标签样式和路由命名 perf: 优化前端页面加载速度和响应时间
294 lines
9.9 KiB
TypeScript
294 lines
9.9 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { LoginPage } from './pages/LoginPage';
|
|
import { TestStabilityHelper } from './helpers/TestStabilityHelper';
|
|
import { TestDataManager } from './helpers/TestDataManager';
|
|
|
|
test.describe('测试稳定性优化示例', () => {
|
|
let loginPage: LoginPage;
|
|
let stabilityHelper: TestStabilityHelper;
|
|
let dataManager: TestDataManager;
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
loginPage = new LoginPage(page);
|
|
stabilityHelper = new TestStabilityHelper(page);
|
|
dataManager = new TestDataManager(page);
|
|
|
|
await dataManager.setupTestData();
|
|
});
|
|
|
|
test.afterEach(async ({ page }) => {
|
|
console.log('Test cleanup started');
|
|
await dataManager.cleanup();
|
|
console.log('Test cleanup completed');
|
|
});
|
|
|
|
test('STABILITY-001: 使用稳定性辅助工具进行登录', async ({ page }) => {
|
|
await test.step('使用安全导航访问登录页', async () => {
|
|
await stabilityHelper.safeNavigate('/login');
|
|
});
|
|
|
|
await test.step('使用安全填充输入用户名', async () => {
|
|
await stabilityHelper.safeFill('[placeholder="请输入用户名"]', 'admin');
|
|
});
|
|
|
|
await test.step('使用安全填充输入密码', async () => {
|
|
await stabilityHelper.safeFill('[placeholder="请输入密码"]', 'admin123');
|
|
});
|
|
|
|
await test.step('使用安全点击登录按钮', async () => {
|
|
await stabilityHelper.safeClick('.el-button--primary');
|
|
});
|
|
|
|
await test.step('等待URL变化到dashboard', async () => {
|
|
await stabilityHelper.waitForURL(/.*dashboard/);
|
|
});
|
|
|
|
await test.step('验证登录成功', async () => {
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-002: 使用数据管理器生成测试数据', async ({ page }) => {
|
|
const testUsername = dataManager.generateTestUsername();
|
|
const testEmail = dataManager.generateTestEmail();
|
|
const testConfigName = dataManager.generateTestConfigName();
|
|
const testNotificationTitle = dataManager.generateTestNotificationTitle();
|
|
|
|
console.log('Generated test data:', {
|
|
username: testUsername,
|
|
email: testEmail,
|
|
configName: testConfigName,
|
|
notificationTitle: testNotificationTitle,
|
|
});
|
|
|
|
await test.step('验证生成的数据唯一性', async () => {
|
|
expect(testUsername).toContain('testuser_');
|
|
expect(testEmail).toContain('@novalon-test.com');
|
|
expect(testConfigName).toContain('testconfig_');
|
|
expect(testNotificationTitle).toContain('testnotify_');
|
|
});
|
|
|
|
await test.step('验证数据管理器功能', async () => {
|
|
dataManager.set('testKey', 'testValue');
|
|
expect(dataManager.has('testKey')).toBe(true);
|
|
expect(dataManager.get('testKey')).toBe('testValue');
|
|
});
|
|
});
|
|
|
|
test('STABILITY-003: 使用网络空闲等待', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('导航到仪表板', async () => {
|
|
await stabilityHelper.safeNavigate('/dashboard');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('验证页面加载完成', async () => {
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-004: 使用元素可见性等待', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('等待表格元素可见', async () => {
|
|
await stabilityHelper.waitForElementVisible('.el-table');
|
|
});
|
|
|
|
await test.step('验证表格可见', async () => {
|
|
const table = page.locator('.el-table');
|
|
await expect(table).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test('STABILITY-005: 使用安全点击和填充', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('安全点击搜索按钮', async () => {
|
|
await stabilityHelper.safeClick('[placeholder="搜索"]');
|
|
});
|
|
|
|
await test.step('安全填充搜索内容', async () => {
|
|
await stabilityHelper.safeFill('[placeholder="搜索"]', 'test');
|
|
});
|
|
});
|
|
|
|
test('STABILITY-006: 使用加载完成等待', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('导航到需要加载的页面', async () => {
|
|
await stabilityHelper.safeNavigate('/system/config');
|
|
await stabilityHelper.waitForLoadingComplete();
|
|
});
|
|
|
|
await test.step('验证页面加载完成', async () => {
|
|
await expect(page).toHaveURL(/.*system\/config/);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-007: 使用表格数据等待', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('导航到配置页面', async () => {
|
|
await stabilityHelper.safeNavigate('/system/config');
|
|
});
|
|
|
|
await test.step('等待表格数据加载', async () => {
|
|
await stabilityHelper.waitForTableData('.el-table', 1);
|
|
});
|
|
|
|
await test.step('验证表格有数据', async () => {
|
|
const rows = page.locator('.el-table__row');
|
|
const rowCount = await rows.count();
|
|
expect(rowCount).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-008: 使用错误消息检测', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('检查是否有错误消息', async () => {
|
|
const hasError = await stabilityHelper.hasErrorMessage();
|
|
expect(hasError).toBe(false);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-009: 使用文本等待验证', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('等待特定文本出现', async () => {
|
|
await stabilityHelper.waitForText('.el-table', '配置名称');
|
|
});
|
|
|
|
await test.step('验证文本存在', async () => {
|
|
const table = page.locator('.el-table');
|
|
await expect(table).toContainText('配置名称');
|
|
});
|
|
});
|
|
|
|
test('STABILITY-010: 使用数据清理机制', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('注册清理回调', async () => {
|
|
dataManager.registerCleanup(async () => {
|
|
console.log('Custom cleanup callback executed');
|
|
});
|
|
});
|
|
|
|
await test.step('验证数据管理器状态', async () => {
|
|
const summary = dataManager.getTestSummary();
|
|
expect(summary.cleanupCallbacksCount).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-011: 使用滚动到视图功能', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('导航到有滚动内容的页面', async () => {
|
|
await stabilityHelper.safeNavigate('/system/config');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('滚动元素到视图', async () => {
|
|
const table = page.locator('.el-table');
|
|
await stabilityHelper.safeScrollIntoView('.el-table');
|
|
});
|
|
|
|
await test.step('验证表格可见', async () => {
|
|
await expect(page.locator('.el-table')).toBeVisible();
|
|
});
|
|
});
|
|
|
|
test('STABILITY-012: 使用悬停功能', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('安全悬停在元素上', async () => {
|
|
await stabilityHelper.safeHover('.el-button');
|
|
});
|
|
});
|
|
|
|
test('STABILITY-013: 使用元素不可见等待', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('等待加载元素消失', async () => {
|
|
await stabilityHelper.waitForLoadingComplete();
|
|
await stabilityHelper.waitForElementNotVisible('.el-loading-mask', 5000);
|
|
});
|
|
});
|
|
|
|
test('STABILITY-014: 使用截图功能', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('截取页面截图', async () => {
|
|
await stabilityHelper.takeScreenshot('dashboard_after_login');
|
|
});
|
|
});
|
|
|
|
test('STABILITY-015: 使用存储清理功能', async ({ page }) => {
|
|
await test.step('登录系统', async () => {
|
|
await loginPage.goto();
|
|
await loginPage.login('admin', 'admin123');
|
|
await stabilityHelper.waitForNetworkIdle();
|
|
});
|
|
|
|
await test.step('清理本地存储', async () => {
|
|
await stabilityHelper.clearLocalStorage();
|
|
await stabilityHelper.clearSessionStorage();
|
|
});
|
|
|
|
await test.step('验证存储已清理', async () => {
|
|
const localStorage = await page.evaluate(() => localStorage.length);
|
|
const sessionStorage = await page.evaluate(() => sessionStorage.length);
|
|
expect(localStorage).toBe(0);
|
|
expect(sessionStorage).toBe(0);
|
|
});
|
|
});
|
|
}); |