feat: FastAPI+SSE API server, JRXML auto-reorder, session integrity fixes
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
||||
"""
|
||||
JRXML Agent E2E test — Playwright automation.
|
||||
Tests: page load, upload image, send message, wait for response.
|
||||
Usage: python test_e2e.py
|
||||
Prerequisites: Servers must be running (start.bat or with_server.py)
|
||||
"""
|
||||
import os, sys, time, base64, tempfile
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
FRONTEND = "http://localhost:5173"
|
||||
API = "http://localhost:8000"
|
||||
TEST_IMAGE = r"D:\Idea Project\agent_jrxml\test_invoice_e2e.png"
|
||||
|
||||
def run():
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page(viewport={"width": 1280, "height": 900})
|
||||
|
||||
# Capture console errors
|
||||
errors = []
|
||||
page.on("console", lambda msg: errors.append(msg.text) if msg.type == "error" else None)
|
||||
|
||||
# 1. Navigate and wait
|
||||
print("[1] Loading frontend...")
|
||||
page.goto(FRONTEND, timeout=15000)
|
||||
page.wait_for_load_state("networkidle")
|
||||
page.wait_for_timeout(1000)
|
||||
|
||||
# Screenshot initial state
|
||||
page.screenshot(path=r"D:\Idea Project\agent_jrxml\e2e_01_initial.png", full_page=True)
|
||||
print(" Screenshot: e2e_01_initial.png")
|
||||
|
||||
# Verify sidebar loads
|
||||
sidebar = page.locator(".sidebar")
|
||||
assert sidebar.is_visible(), "Sidebar not visible"
|
||||
print(" OK: Sidebar visible")
|
||||
|
||||
# 2. Create new session (click +)
|
||||
print("[2] Creating new session...")
|
||||
page.locator(".btn-icon").click()
|
||||
page.wait_for_timeout(500)
|
||||
page.screenshot(path=r"D:\Idea Project\agent_jrxml\e2e_02_session.png")
|
||||
print(" OK: New session created")
|
||||
|
||||
# 3. Upload test image
|
||||
print("[3] Uploading test image...")
|
||||
upload_input = page.locator('input[type="file"]')
|
||||
upload_input.set_input_files(TEST_IMAGE)
|
||||
page.wait_for_timeout(500)
|
||||
# Verify file chip appears
|
||||
chip = page.locator(".chip").first
|
||||
assert chip.is_visible(), "File chip not visible after upload"
|
||||
print(f" OK: File chip visible — {chip.inner_text()}")
|
||||
|
||||
# 4. Type message and send
|
||||
print('[4] Sending message...')
|
||||
textarea = page.locator("textarea").first
|
||||
textarea.fill("根据这张图片生成车历卡报表模板")
|
||||
page.wait_for_timeout(200)
|
||||
page.screenshot(path=r"D:\Idea Project\agent_jrxml\e2e_03_input.png")
|
||||
|
||||
# Click send button or press Enter
|
||||
page.locator('button[type="submit"]').click()
|
||||
print(" Sent!")
|
||||
|
||||
# 5. Wait for streaming response
|
||||
print("[5] Waiting for AI response...")
|
||||
try:
|
||||
# Wait up to 3 minutes for a success or error message
|
||||
page.wait_for_selector('.message.assistant', timeout=180000)
|
||||
page.wait_for_timeout(2000)
|
||||
page.screenshot(path=r"D:\Idea Project\agent_jrxml\e2e_04_response.png", full_page=True)
|
||||
|
||||
# Check for success/error
|
||||
messages = page.locator('.message.assistant').all()
|
||||
for m in messages:
|
||||
text = m.inner_text()
|
||||
if "成功" in text:
|
||||
print(f" ✅ SUCCESS: {text[:100]}")
|
||||
elif "失败" in text or "错误" in text:
|
||||
print(f" ❌ ERROR: {text[:100]}")
|
||||
elif "JRXML" in text:
|
||||
print(f" 📄 JRXML generated ({len(text)} chars)")
|
||||
except Exception as e:
|
||||
page.screenshot(path=r"D:\Idea Project\agent_jrxml\e2e_04_timeout.png", full_page=True)
|
||||
print(f" ⚠️ Timeout waiting for response: {e}")
|
||||
|
||||
# 6. Check download button
|
||||
print("[6] Checking download button...")
|
||||
download_btn = page.locator(".btn-download").first
|
||||
if download_btn.is_visible():
|
||||
text = download_btn.inner_text()
|
||||
print(f" Download button: '{text}'")
|
||||
if "暂无" not in text:
|
||||
print(" ✅ Download link available!")
|
||||
else:
|
||||
print(" ⚠️ Download shows '暂无下载文件'")
|
||||
else:
|
||||
print(" ⚠️ Download button not found")
|
||||
|
||||
# Console errors
|
||||
if errors:
|
||||
print(f"\n[!] Console errors ({len(errors)}):")
|
||||
for e in errors[:5]:
|
||||
print(f" {e[:200]}")
|
||||
else:
|
||||
print("\n ✅ No console errors")
|
||||
|
||||
print("\n=== E2E test complete ===")
|
||||
browser.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.makedirs(r"D:\Idea Project\agent_jrxml", exist_ok=True)
|
||||
run()
|
||||
Reference in New Issue
Block a user