97 lines
3.1 KiB
JavaScript
97 lines
3.1 KiB
JavaScript
// 快速自动化测试 - 排查连接超时问题
|
|
const automator = require('miniprogram-automator');
|
|
|
|
async function runTest() {
|
|
console.log('连接 ws://localhost:9420 ...');
|
|
|
|
const mp = await automator.connect({
|
|
wsEndpoint: 'ws://localhost:9420',
|
|
});
|
|
console.log('✅ 连接成功');
|
|
|
|
// 尝试获取系统信息
|
|
console.log('\n[1] 获取系统信息...');
|
|
const sysInfo = await mp.systemInfo();
|
|
console.log('系统信息:', JSON.stringify(sysInfo, null, 2));
|
|
|
|
// 尝试获取页面栈
|
|
console.log('\n[2] 获取页面栈...');
|
|
const pages = await mp.pageStack();
|
|
console.log('页面栈:', pages.map(p => p.path));
|
|
|
|
// 获取当前页面
|
|
console.log('\n[3] 获取当前页面...');
|
|
const currentPage = await mp.currentPage();
|
|
console.log('当前页面:', currentPage.path);
|
|
|
|
// 获取页面数据
|
|
console.log('\n[4] 获取页面数据...');
|
|
const data = await currentPage.data();
|
|
console.log('页面数据 keys:', Object.keys(data));
|
|
|
|
// 截图
|
|
console.log('\n[5] 截图...');
|
|
await mp.screenshot({ path: 'test/screenshots/quick-test.png' });
|
|
console.log('✅ 截图已保存');
|
|
|
|
// 设置控制台监听
|
|
console.log('\n[6] 设置控制台监听并重新加载...');
|
|
const warnings = [];
|
|
const errors = [];
|
|
mp.on('console', msg => {
|
|
const args = msg.args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ');
|
|
if (msg.type === 'error') {
|
|
errors.push(args);
|
|
} else if (msg.type === 'warn') {
|
|
warnings.push(args);
|
|
}
|
|
});
|
|
|
|
// 导航到活动详情页
|
|
console.log('\n[7] 导航到活动详情页...');
|
|
const detailPage = await mp.navigateTo('/pages/activity-detail/index?id=activity-6');
|
|
console.log('✅ 导航成功:', detailPage.path);
|
|
|
|
// 等待数据加载
|
|
console.log('\n[8] 等待数据加载 (8秒)...');
|
|
await new Promise(r => setTimeout(r, 8000));
|
|
|
|
// 获取页面数据
|
|
const detailData = await detailPage.data();
|
|
console.log('活动标题:', detailData.activity?.title);
|
|
console.log('AI推荐:', detailData.aiRecommendation ? '已加载' : '未加载');
|
|
if (detailData.aiRecommendation) {
|
|
console.log('参与者数量:', detailData.aiRecommendation.participants?.length || 0);
|
|
}
|
|
|
|
// 截图
|
|
await mp.screenshot({ path: 'test/screenshots/activity-detail.png' });
|
|
console.log('✅ 活动详情截图已保存');
|
|
|
|
// 返回首页
|
|
await mp.navigateBack();
|
|
await new Promise(r => setTimeout(r, 2000));
|
|
|
|
// 输出警告和错误
|
|
console.log('\n========================================');
|
|
console.log(`警告: ${warnings.length}`);
|
|
console.log(`错误: ${errors.length}`);
|
|
if (warnings.length > 0) {
|
|
console.log('\n警告详情:');
|
|
warnings.slice(0, 10).forEach((w, i) => console.log(` ${i + 1}. ${w}`));
|
|
}
|
|
if (errors.length > 0) {
|
|
console.log('\n错误详情:');
|
|
errors.slice(0, 10).forEach((e, i) => console.log(` ${i + 1}. ${e}`));
|
|
}
|
|
console.log('========================================');
|
|
|
|
await mp.close();
|
|
console.log('\n测试完成');
|
|
}
|
|
|
|
runTest().catch(e => {
|
|
console.error('测试失败:', e.message);
|
|
process.exit(1);
|
|
});
|