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.
54 lines
1.8 KiB
54 lines
1.8 KiB
|
2 weeks ago
|
import sys, io, json
|
||
|
|
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\03-list.html').as_uri()
|
||
|
|
screenshot_path = r'D:\code\crm-backend-matt\.scratch\opportunity-verify\frontend\03-list-result.png'
|
||
|
|
|
||
|
|
with sync_playwright() as p:
|
||
|
|
browser = p.chromium.launch(headless=True)
|
||
|
|
page = browser.new_page()
|
||
|
|
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.run-all')
|
||
|
|
page.wait_for_timeout(6000)
|
||
|
|
page.wait_for_load_state('networkidle')
|
||
|
|
|
||
|
|
page.screenshot(path=screenshot_path, full_page=True)
|
||
|
|
|
||
|
|
# 收集每个 case 的断言 + HTTP 状态第一行
|
||
|
|
cases = [
|
||
|
|
('mine', '① /page MINE'),
|
||
|
|
('recent', '② /page RECENT'),
|
||
|
|
('pool', '③ /page PUBLIC_POOL'),
|
||
|
|
('manage', '④ /page MANAGE'),
|
||
|
|
('rv', '⑤ /recent-visits/page'),
|
||
|
|
('board-summary','⑥ /board/stage-summary'),
|
||
|
|
('board-cards', '⑦ /board/cards'),
|
||
|
|
('touch', '⑧ /recent-visits/touch'),
|
||
|
|
]
|
||
|
|
|
||
|
|
print('=' * 60)
|
||
|
|
for key, label in cases:
|
||
|
|
items = page.locator(f'#assert-{key} li').all()
|
||
|
|
raw = page.locator(f'#result-{key}').inner_text()
|
||
|
|
first = raw.split('\n')[0].strip()
|
||
|
|
print(f'\n【{label}】{first}')
|
||
|
|
for li in items:
|
||
|
|
print(' ' + li.inner_text())
|
||
|
|
|
||
|
|
if errors:
|
||
|
|
print('\n=== Console 错误 ===')
|
||
|
|
for e in errors:
|
||
|
|
print(e)
|
||
|
|
else:
|
||
|
|
print('\n(无 console 错误)')
|
||
|
|
|
||
|
|
browser.close()
|