You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

47 lines
1.4 KiB

import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
from pathlib import Path
from playwright.sync_api import sync_playwright
html_path = Path(r'D:\code\crm-backend-matt\.scratch\opportunity-verify\frontend\index.html').as_uri()
screenshot_path = r'D:\code\crm-backend-matt\.scratch\opportunity-verify\frontend\scaffold-check.png'
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
ctx = browser.new_context()
page = ctx.new_page()
# 收集 console 错误
errors = []
page.on('console', lambda msg: errors.append(msg.text) if msg.type == 'error' else None)
page.goto(html_path)
page.wait_for_load_state('networkidle')
# 点击运行自检
page.click('button')
page.wait_for_timeout(3000) # 等网络请求完成
page.wait_for_load_state('networkidle')
# 截图
page.screenshot(path=screenshot_path, full_page=True)
# 读取断言结果
items = page.locator('#assertions li').all()
result_text = page.locator('#result').inner_text()
print('=== 断言结果 ===')
for li in items:
print(li.inner_text())
print('\n=== 响应预览(前 500 字符)===')
print(result_text[:500])
if errors:
print('\n=== Console 错误 ===')
for e in errors:
print(e)
else:
print('\n(无 console 错误)')
browser.close()