Files
jiaoyu/frontend/_verify_404.cjs
Zhang Jing Xuan 0841b1a103 智教助手平台:完整初始化
- 前端:Vue3 + TS + Element Plus,24 个页面路由(课件/组题/教案/动画/思维导图/作文批改/命题/课堂/资源/社区等)
- 后端:FastAPI + SQLAlchemy + SQLite,17 个路由模块,AI 服务层含降级模板
- AI:glm-5.x 推理模型已禁用思维链,确保输出真实内容
- 修复:ai_service 两处请求体注入 enable_thinking/thinking disabled
- 测试账号:13900999999 / test1234
2026-07-29 16:29:10 +08:00

56 lines
2.7 KiB
JavaScript

const { chromium } = require('playwright-core');
(async () => {
const CHROME = String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`;
const browser = await chromium.launch({ executablePath: CHROME, headless: true });
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const errs = [];
page.on('pageerror', e => errs.push(e.message));
page.on('console', m => { if (m.type()==='error') errs.push(m.text()); });
// 1) Verify SEO meta tags on a normal page
await page.goto('http://127.0.0.1:5175/login');
await page.waitForTimeout(2000);
const desc = await page.locator('meta[name="description"]').getAttribute('content').catch(()=> '');
const ogTitle = await page.locator('meta[property="og:title"]').getAttribute('content').catch(()=> '');
const themeColor = await page.locator('meta[name="theme-color"]').getAttribute('content').catch(()=> '');
const noscript = await page.locator('noscript').count();
console.log('META description:', desc ? desc.slice(0,50)+'...' : 'MISSING');
console.log('META og:title:', ogTitle || 'MISSING');
console.log('META theme-color:', themeColor || 'MISSING');
console.log('noscript fallback:', noscript > 0 ? 'PRESENT' : 'MISSING');
// 2) Test shallow 404 (within AppLayout)
await page.goto('http://127.0.0.1:5175/nonexistent-page');
await page.waitForTimeout(1500);
const title404 = (await page.locator('.nf-title').textContent().catch(()=> '')) || '';
const code404 = (await page.locator('.nf-code').textContent().catch(()=> '')) || '';
console.log('\nSHALLOW 404 (/nonexistent-page):');
console.log(' nf-code:', code404.trim());
console.log(' nf-title:', title404.trim());
console.log(' has home btn:', await page.locator('.nf-btn.primary').count());
// 3) Test deep 404
await page.goto('http://127.0.0.1:5175/foo/bar/baz/deep');
await page.waitForTimeout(1500);
const deepTitle = (await page.locator('.nf-title').textContent().catch(()=> '')) || '';
console.log('\nDEEP 404 (/foo/bar/baz/deep):');
console.log(' nf-title:', deepTitle.trim());
// 4) Test that clicking "返回首页" works
await page.goto('http://127.0.0.1:5175/xyz');
await page.waitForTimeout(1500);
await page.locator('.nf-btn.primary').click();
await page.waitForTimeout(1500);
console.log('\nCLICK HOME -> url:', page.url());
console.log(' landed on home:', page.url().endsWith('/login') || page.url().endsWith('/5175/'));
// 5) screenshot
await page.goto('http://127.0.0.1:5175/nonexistent');
await page.waitForTimeout(1500);
await page.screenshot({ path: '../audit_shots/_404_page.png' });
console.log('\nERRORS:', errs.length);
if (errs.length) console.log('ERR_DETAIL:', [...new Set(errs)].slice(0,5));
await browser.close();
})();