from playwright.sync_api import sync_playwright import json results = {'pages': [], 'interactions': [], 'issues': []} with sync_playwright() as p: browser = p.chromium.launch(headless=True) console_messages = [] def handle_console(msg): console_messages.append({'type': msg.type, 'text': msg.text[:500]}) def handle_pageerror(err): console_messages.append({'type': 'pageerror', 'text': str(err)[:500]}) # === Test Home Page === page = browser.new_page() page.on('console', handle_console) page.on('pageerror', handle_pageerror) console_messages.clear() page.goto('http://localhost:5177/#/', wait_until='networkidle', timeout=30000) page.wait_for_timeout(3000) body_text = page.inner_text('body') results['pages'].append({ 'name': '黄历搜索首页', 'url': page.url, 'body_text': body_text[:1000], 'console_errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')], 'warnings': [m for m in console_messages if m['type'] == 'warning'] }) page.screenshot(path='/tmp/eis-dog-1-home.png', full_page=True) # === Test Add Condition === console_messages.clear() add_btn = page.locator('text=添加条件').first if add_btn.count() > 0: add_btn.click() page.wait_for_timeout(1500) body_after = page.inner_text('body') results['interactions'].append({ 'action': 'add_search_condition', 'has_type_selector': '宜' in body_after or '忌' in body_after, 'has_items': '祭祀' in body_after or '嫁娶' in body_after, 'errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')] }) page.screenshot(path='/tmp/eis-dog-2-add-condition.png', full_page=True) # === Test Template Category === console_messages.clear() wedding_tab = page.locator('text=婚嫁').first if wedding_tab.count() > 0: wedding_tab.click() page.wait_for_timeout(1000) body_after = page.inner_text('body') results['interactions'].append({ 'action': 'select_wedding_category', 'shows_wedding_only': '嫁娶吉日' in body_after, 'errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')] }) # === Test Search === console_messages.clear() all_tab = page.locator('text=全部').first if all_tab.count() > 0: all_tab.click() page.wait_for_timeout(500) search_btn = page.locator('text=搜索').last if search_btn.count() > 0: search_btn.click() page.wait_for_timeout(2000) body_after = page.inner_text('body') results['interactions'].append({ 'action': 'execute_search', 'has_results_or_empty_state': '暂无数据' in body_after or '搜索结果' in body_after or '匹配' in body_after, 'errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')] }) page.screenshot(path='/tmp/eis-dog-3-search.png', full_page=True) # === Test Ziwei Page === console_messages.clear() ziwei_nav = page.locator('text=紫微').first if ziwei_nav.count() > 0: ziwei_nav.click() page.wait_for_timeout(5000) try: page.wait_for_load_state('networkidle', timeout=10000) except: pass page.wait_for_timeout(2000) body_text = page.inner_text('body') results['pages'].append({ 'name': '紫微斗数页面', 'url': page.url, 'body_text': body_text[:1000], 'console_errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')], 'warnings': [m for m in console_messages if m['type'] == 'warning'] }) page.screenshot(path='/tmp/eis-dog-4-ziwei.png', full_page=True) # === Test Fortune Page === console_messages.clear() fortune_nav = page.locator('text=运势').first if fortune_nav.count() > 0: fortune_nav.click() page.wait_for_timeout(5000) try: page.wait_for_load_state('networkidle', timeout=10000) except: pass page.wait_for_timeout(2000) body_text = page.inner_text('body') results['pages'].append({ 'name': '运势页面', 'url': page.url, 'body_text': body_text[:1000], 'console_errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')], 'warnings': [m for m in console_messages if m['type'] == 'warning'] }) page.screenshot(path='/tmp/eis-dog-5-fortune.png', full_page=True) # === Test Navigate Back === console_messages.clear() almanac_nav = page.locator('text=黄历').first if almanac_nav.count() > 0: almanac_nav.click() page.wait_for_timeout(3000) body_text = page.inner_text('body') results['interactions'].append({ 'action': 'navigate_back_home', 'home_loaded': '搜索模板' in body_text, 'errors': [m for m in console_messages if m['type'] in ('error', 'pageerror')] }) browser.close() print(json.dumps(results, ensure_ascii=False, indent=2)) total_errors = sum(len(p.get('console_errors', [])) for p in results['pages']) total_errors += sum(len(i.get('errors', [])) for i in results['interactions']) print(f"\nTotal console errors: {total_errors}") print(f"Pages tested: {len(results['pages'])}") print(f"Interactions tested: {len(results['interactions'])}")