test(file-summary): 增加 Playwright 端到端测试
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,4 +6,5 @@ db.sqlite3
|
|||||||
staticfiles/
|
staticfiles/
|
||||||
media/
|
media/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
.tmp/
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ openpyxl>=3.1
|
|||||||
xlrd>=2.0
|
xlrd>=2.0
|
||||||
olefile>=0.47
|
olefile>=0.47
|
||||||
py7zr>=0.21
|
py7zr>=0.21
|
||||||
|
playwright>=1.60
|
||||||
|
|||||||
47
tests/test_file_summary_e2e.py
Normal file
47
tests/test_file_summary_e2e.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from review_agent.models import Conversation
|
||||||
|
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.django_db
|
||||||
|
|
||||||
|
|
||||||
|
def _browser_path() -> str | None:
|
||||||
|
candidates = [
|
||||||
|
Path(r"C:\Program Files\Google\Chrome\Application\chrome.exe"),
|
||||||
|
Path(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"),
|
||||||
|
]
|
||||||
|
for candidate in candidates:
|
||||||
|
if candidate.exists():
|
||||||
|
return str(candidate)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def test_file_summary_panel_desktop_and_mobile_with_playwright(live_server, django_user_model):
|
||||||
|
playwright_api = pytest.importorskip("playwright.sync_api")
|
||||||
|
executable_path = _browser_path()
|
||||||
|
if not executable_path:
|
||||||
|
pytest.skip("No Chrome or Edge executable available for Playwright E2E.")
|
||||||
|
|
||||||
|
user = django_user_model.objects.create_user(username="e2e_user", password="e2e-pass-123")
|
||||||
|
Conversation.objects.create(user=user, title="E2E 会话")
|
||||||
|
|
||||||
|
with playwright_api.sync_playwright() as p:
|
||||||
|
browser = p.chromium.launch(headless=True, executable_path=executable_path)
|
||||||
|
page = browser.new_page(viewport={"width": 1440, "height": 900})
|
||||||
|
page.goto(f"{live_server.url}/login/")
|
||||||
|
page.fill('input[name="username"]', "e2e_user")
|
||||||
|
page.fill('input[name="password"]', "e2e-pass-123")
|
||||||
|
page.click('button[type="submit"]')
|
||||||
|
page.wait_for_url(f"{live_server.url}/")
|
||||||
|
|
||||||
|
playwright_api.expect(page.locator("#summaryPanel")).to_be_visible()
|
||||||
|
playwright_api.expect(page.locator("#uploadDropzone")).to_be_visible()
|
||||||
|
playwright_api.expect(page.locator("#workflowCardList")).to_be_visible()
|
||||||
|
|
||||||
|
page.set_viewport_size({"width": 390, "height": 844})
|
||||||
|
playwright_api.expect(page.locator("#summaryPanel")).to_be_visible()
|
||||||
|
playwright_api.expect(page.locator("#sidebar")).not_to_be_in_viewport()
|
||||||
|
browser.close()
|
||||||
Reference in New Issue
Block a user