// 加载环境变量 require('../../config/env'); const { test } = require('@playwright/test'); const TestController = require('../../src/controllers/TestController'); const menuDataService = require('../../src/services/MenuDataService'); test.describe('菜单可访问性测试', () => { let controller; test.beforeAll(async () => { controller = new TestController(); // 打印环境变量,用于调试 console.log('BASE_URL:', process.env.BASE_URL); }); test('收集菜单数据', async () => { const menuData = await controller.collectMenuData(); console.log(`成功收集 ${menuData.length} 个菜单项`); }); test('批量测试菜单', async () => { // 清理之前的进度 menuDataService.saveProgress([]); let retryCount = 0; const maxRetries = parseInt(process.env.TEST_RETRY_COUNT || '3', 10); while (true) { const batch = controller.getNextBatch(); if (!batch || batch.length === 0) { const finalProgress = controller.getTestProgress(); if (finalProgress.completed < finalProgress.total && retryCount < maxRetries) { console.log(`\n还有未完成的测试,尝试重试 (${retryCount + 1}/${maxRetries})...`); retryCount++; continue; } console.log('\n所有测试完成!'); console.log(`最终进度: ${finalProgress.completed}/${finalProgress.total}`); break; } // 显示当前进度 const currentProgress = controller.getTestProgress(); console.log(`\n当前进度: ${currentProgress.completed}/${currentProgress.total}`); // 执行当前批次 await controller.runBatchTest(batch); // 批次间暂停 const batchInterval = parseInt(process.env.TEST_BATCH_INTERVAL || '2000', 10); await new Promise(resolve => setTimeout(resolve, batchInterval)); } }); });