92 lines
3.3 KiB
Python
92 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Desktop E2E Test for FilePreview iframe height fix
|
|
Tests HTML and Markdown report preview in FilePreview component
|
|
"""
|
|
from playwright.sync_api import sync_playwright
|
|
import time
|
|
import os
|
|
import sys
|
|
|
|
# Fix Unicode output for Windows
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
SCREENSHOT_DIR = r"D:\Idea Project\publish\agent_test\screenshots"
|
|
BASE_URL = "http://localhost:41734"
|
|
|
|
def main():
|
|
os.makedirs(SCREENSHOT_DIR, exist_ok=True)
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
context = browser.new_context(viewport={"width": 1280, "height": 800})
|
|
page = context.new_page()
|
|
|
|
print("Step 1: Navigating to home page...")
|
|
page.goto(BASE_URL)
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(2)
|
|
page.screenshot(path=os.path.join(SCREENSHOT_DIR, "01_home_page.png"))
|
|
print(" Screenshot 01: Home page")
|
|
|
|
# Step 2: Click on project card
|
|
print("Step 2: Clicking on project card...")
|
|
try:
|
|
page.click('text=项目一')
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(2)
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
page.screenshot(path=os.path.join(SCREENSHOT_DIR, "02_project_detail.png"))
|
|
print(" Screenshot 02: Project detail page")
|
|
|
|
# Step 3: Click on HTML report
|
|
print("Step 3: Clicking on HTML report (2026-05-22 日报.html)...")
|
|
try:
|
|
page.click('text=2026-05-22')
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(2)
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
page.screenshot(path=os.path.join(SCREENSHOT_DIR, "03_html_preview.png"))
|
|
print(" Screenshot 03: HTML preview")
|
|
|
|
# Check iframe height
|
|
print("Step 4: Checking iframe dimensions...")
|
|
try:
|
|
iframe = page.locator('iframe').first
|
|
if iframe:
|
|
box = iframe.bounding_box(timeout=5000)
|
|
if box:
|
|
h = box.get('height', 0)
|
|
w = box.get('width', 0)
|
|
print(f" iframe dimensions: {w}x{h}px")
|
|
if h >= 300:
|
|
print(" PASS: iframe height >= 300px")
|
|
else:
|
|
print(f" WARN: iframe height is small: {h}px")
|
|
except Exception as e:
|
|
print(f" Error checking iframe: {e}")
|
|
|
|
# Step 5: Click on Markdown report
|
|
print("Step 5: Clicking on Markdown report (2026-05-21 日报.md)...")
|
|
try:
|
|
page.click('text=2026-05-21')
|
|
page.wait_for_load_state("networkidle")
|
|
time.sleep(2)
|
|
except Exception as e:
|
|
print(f" Error: {e}")
|
|
page.screenshot(path=os.path.join(SCREENSHOT_DIR, "04_md_preview.png"))
|
|
print(" Screenshot 04: Markdown preview")
|
|
|
|
# Final screenshot
|
|
final_path = os.path.join(SCREENSHOT_DIR, "desktop-preview-test.png")
|
|
page.screenshot(path=final_path, full_page=False)
|
|
print(f"\nDONE: Final screenshot saved to:\n {final_path}")
|
|
|
|
browser.close()
|
|
print("Test completed successfully!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|