from playwright.sync_api import sync_playwright import time import os def dismiss_vite_error(page): try: page.evaluate("document.querySelector('vite-error-overlay')?.remove()") time.sleep(0.3) except: pass def test_articles(): os.makedirs('/tmp/frontend_test', exist_ok=True) with sync_playwright() as p: browser = p.chromium.launch(headless=True) context = browser.new_context(viewport={"width": 1400, "height": 900}) page = context.new_page() print("=" * 60) print("测试文章页面 - 虚假数据已删除") print("=" * 60) page.goto('http://localhost:5173/articles', wait_until='load', timeout=15000) time.sleep(2) dismiss_vite_error(page) page.screenshot(path='/tmp/frontend_test/articles_no_stats.png', full_page=True) print(" ✓ 文章页面截图已保存") # 检查是否还有统计卡片 stat_items = page.locator('.articles-stat-item') if stat_items.count() > 0: print(f" ⚠ 仍有 {stat_items.count()} 个统计卡片") else: print(" ✓ 统计卡片已完全删除") # 检查是否还有统计行 stats_row = page.locator('.articles-stats-row') if stats_row.count() > 0: print(f" ⚠ 仍有统计行存在") else: print(" ✓ 统计行已完全删除") browser.close() print("\n" + "=" * 60) print("测试完成!") print("=" * 60) if __name__ == "__main__": test_articles()