Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
/**
|
|
* Playwright 全局测试设置
|
|
* 在所有测试开始前执行
|
|
*/
|
|
|
|
import { chromium, FullConfig } from '@playwright/test';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
async function globalSetup(config: FullConfig) {
|
|
console.log('🚀 开始全局测试设置...');
|
|
|
|
const browser = await chromium.launch();
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
|
|
try {
|
|
// 检查应用是否可访问
|
|
console.log('📡 检查应用可访问性...');
|
|
await page.goto('http://localhost:5173', { timeout: 30000 });
|
|
|
|
// 等待页面加载完成
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 检查登录页面是否正常显示(更灵活的选择器)
|
|
try {
|
|
await page.waitForSelector(
|
|
'input[placeholder*="用户名"], input[placeholder*="邮箱"], input[placeholder*="账号"], [data-testid="username-input"]',
|
|
{ timeout: 10000 },
|
|
);
|
|
console.log('✅ 应用可正常访问');
|
|
} catch (error) {
|
|
console.log('⚠️ 登录页面检测超时,但应用已启动');
|
|
}
|
|
|
|
// 创建测试数据目录
|
|
const testDataDir = path.join(process.cwd(), 'test-results', 'test-data');
|
|
if (!fs.existsSync(testDataDir)) {
|
|
fs.mkdirSync(testDataDir, { recursive: true });
|
|
console.log('📁 测试数据目录已创建');
|
|
}
|
|
|
|
// 创建截图目录
|
|
const screenshotDir = path.join(
|
|
process.cwd(),
|
|
'test-results',
|
|
'screenshots',
|
|
);
|
|
if (!fs.existsSync(screenshotDir)) {
|
|
fs.mkdirSync(screenshotDir, { recursive: true });
|
|
console.log('📸 截图目录已创建');
|
|
}
|
|
|
|
// 初始化测试计数器
|
|
const testMetrics = {
|
|
startTime: new Date().toISOString(),
|
|
setupCompleted: true,
|
|
testEnvironment: process.env.NODE_ENV || 'test',
|
|
baseURL: 'http://localhost:5173',
|
|
};
|
|
|
|
fs.writeFileSync(
|
|
path.join(testDataDir, 'test-metrics.json'),
|
|
JSON.stringify(testMetrics, null, 2),
|
|
);
|
|
|
|
console.log('🎉 全局测试设置完成');
|
|
} catch (error) {
|
|
console.error('❌ 全局测试设置失败:', error);
|
|
throw error;
|
|
} finally {
|
|
await context.close();
|
|
await browser.close();
|
|
}
|
|
}
|
|
|
|
export default globalSetup;
|