#!/usr/bin/env python3 """ 验证按钮显示修复效果 检查软件开发服务页面的三个CTA按钮是否正常显示文字 """ from playwright.sync_api import sync_playwright import sys def verify_buttons(): with sync_playwright() as p: browser = p.chromium.launch(headless=True) page = browser.new_page() try: # 访问软件开发服务页面 print("🔍 正在访问软件开发服务页面...") page.goto('http://localhost:3000/services/software', timeout=30000) page.wait_for_load_state('networkidle') # 截图保存 screenshot_path = 'test-results/service-page-buttons.png' page.screenshot(path=screenshot_path, full_page=True) print(f"📸 页面截图已保存: {screenshot_path}") # 查找所有 RippleButton(通过文本内容识别) buttons_to_check = [ {"text": "预约演示", "expected": "outline variant with red text"}, {"text": "免费咨询", "expected": "solid red background with white text"}, {"text": "了解详情", "expected": "outline variant with red text"} ] print("\n✅ 按钮验证结果:") all_buttons_found = True for button_info in buttons_to_check: try: # 查找包含指定文本的按钮 button = page.locator(f'a:has-text("{button_info["text"]}"), button:has-text("{button_info["text"]}")').first if button.count() > 0: # 获取按钮的样式信息 button_text = button.inner_text() is_visible = button.is_visible() # 检查按钮是否有可见的文本 text_color = button.evaluate('el => window.getComputedStyle(el).color') bg_color = button.evaluate('el => window.getComputedStyle(el).backgroundColor') print(f"\n ✓ 按钮 '{button_text}':") print(f" - 可见性: {'✅ 可见' if is_visible else '❌ 不可见'}") print(f" - 文字颜色: {text_color}") print(f" - 背景颜色: {bg_color}") print(f" - 预期样式: {button_info['expected']}") # 检查文字是否可见(文字颜色不应与背景色相同) if is_visible and button_text: print(f" - 状态: ✅ 正常显示") else: print(f" - 状态: ❌ 可能存在问题") all_buttons_found = False else: print(f"\n ❌ 未找到按钮: '{button_info['text']}'") all_buttons_found = False except Exception as e: print(f"\n ❌ 检查按钮 '{button_info['text']}' 时出错: {e}") all_buttons_found = False # 额外检查:确保按钮文字不是透明的 print("\n🔍 额外检查:按钮文字透明度...") all_buttons = page.locator('a:has-text("预约演示"), a:has-text("免费咨询"), a:has-text("了解详情")').all() for button in all_buttons: text = button.inner_text() opacity = button.evaluate('el => window.getComputedStyle(el).opacity') print(f" - '{text}' 透明度: {opacity}") if all_buttons_found: print("\n🎉 验证成功!所有按钮都正常显示文字。") return 0 else: print("\n⚠️ 部分按钮可能存在问题,请检查截图。") return 1 except Exception as e: print(f"\n❌ 验证过程中出错: {e}") return 1 finally: browser.close() if __name__ == '__main__': sys.exit(verify_buttons())