68 lines
2.8 KiB
JavaScript
68 lines
2.8 KiB
JavaScript
/**
|
|
* 审计详情页(带参数)- 测试带假 ID 的页面是否优雅降级
|
|
*/
|
|
const automator = require('miniprogram-automator');
|
|
|
|
const DETAIL_PAGES = [
|
|
'pages/appointment/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/article/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/report/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/ai-report/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/mall/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/mall/exchange/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/profile/family-add/index',
|
|
'pages/doctor/patients/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/doctor/consultation/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/doctor/followup/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
'pages/doctor/report/detail/index?id=00000000-0000-0000-0000-000000000000',
|
|
];
|
|
|
|
async function main() {
|
|
console.log('连接...');
|
|
const mp = await automator.connect({ wsEndpoint: 'ws://localhost:9420' });
|
|
|
|
const results = { ok: [], crash: [], login: [] };
|
|
|
|
for (const pageUrl of DETAIL_PAGES) {
|
|
const pagePath = pageUrl.split('?')[0];
|
|
try {
|
|
await mp.reLaunch(`/${pageUrl}`);
|
|
await new Promise(r => setTimeout(r, 2000));
|
|
const current = await mp.currentPage();
|
|
|
|
if (current.path === pagePath) {
|
|
// 检查页面是否有错误提示或空状态
|
|
const content = await mp.evaluate(() => {
|
|
const texts = [];
|
|
document.querySelectorAll && document.querySelectorAll('.error-state, .empty-state, [class*="error"], [class*="empty"]').forEach(el => {
|
|
texts.push(el.textContent);
|
|
});
|
|
return texts.length > 0 ? texts.join('; ') : 'loaded';
|
|
}).catch(() => 'loaded');
|
|
results.ok.push(`${pagePath} (${content.slice(0, 30)})`);
|
|
console.log(` OK: ${pagePath} - ${content.slice(0, 40)}`);
|
|
} else if (current.path === 'pages/login/index') {
|
|
results.login.push(pagePath);
|
|
console.log(` AUTH: ${pagePath} → login`);
|
|
} else {
|
|
results.crash.push(`${pagePath} → ${current.path}`);
|
|
console.log(` REDIR: ${pagePath} → ${current.path}`);
|
|
}
|
|
} catch (e) {
|
|
results.crash.push(`${pagePath}: ${e.message.slice(0, 50)}`);
|
|
console.log(` ERR: ${pagePath} - ${e.message.slice(0, 40)}`);
|
|
}
|
|
}
|
|
|
|
console.log(`\n===== 详情页审计 =====`);
|
|
console.log(`正常: ${results.ok.length}`);
|
|
console.log(`需登录: ${results.login.length}`);
|
|
console.log(`异常: ${results.crash.length}`);
|
|
results.crash.forEach(p => console.log(` 异常: ${p}`));
|
|
results.login.forEach(p => console.log(` 需登录: ${p}`));
|
|
|
|
await mp.disconnect();
|
|
}
|
|
|
|
main().catch(e => { console.error(e); process.exit(1); });
|