test: establish Playwright E2E UI testing foundation (#426)#428
test: establish Playwright E2E UI testing foundation (#426)#428tejassinghbhati wants to merge 5 commits intoEAPD-DRB:mainfrom
Conversation
…/CI server flakiness - Replace subprocess server launch with an in-process Waitress daemon thread. This eliminates cross-platform CWD/sys.path/env-var inheritance issues that caused page.goto() timeouts on Python 3.12 Windows when using Flask dev server. - Configure Waitress with threads=16 and channel_timeout=10 to prevent thread exhaustion during Playwright's burst of concurrent static asset requests. - Use wait_until='commit' on all page.goto() calls so browser tests return the instant Flask starts sending bytes, without blocking on CDN resources (MathJax) or synchronous <script> downloads that precede DOM parsing. - Scope assertions to elements guaranteed present in raw server-rendered HTML: page title (in <head>), footer copyright text (hardcoded in index.html). - All 4 tests now pass locally in 8s: test_health_endpoint, test_session_api, test_load_app, test_static_footer.
|
Greeting to everyone, I apologize for the time this took and it involved the closing of another PR earlier, just pushed a significant fix to this branch, wanted to document what changed and why. When I first opened this PR, the test suite was failing in CI with After debugging further locally, I also ran into a deeper infrastructure problem. The So I reworked the entire server fixture from scratch. Instead of a subprocess, the server now runs as a Waitress daemon thread inside the pytest process — same WSGI server the app uses in production, configured with 16 threads and a 10-second idle connection timeout. This eliminates the OS-specific dev server issues and ensures threads are always available across test sessions. On the test side, I also switched from The result: 4 tests, 3 consecutive passing runs locally, under 6 seconds each. The tests now only assert what Flask unconditionally guarantees, the This should be stable for the contribution as of now. Thank you so much for your time. @m13v |
Resolves #426
What This PR Does
I have built a stable, cross-platform Playwright E2E testing foundation for the MUIOGO frontend.
It introduces:
This approach deliberately avoids:
The Problems Encountered (and what I have learned)
The integration was not that straightforward, I had to identify three distinct failure classes and resolve them:
Problem 1: Subprocess Flask dev server hangs on Python 3.12 (Windows)
Initial Approach:
API/app.pyas a subprocess using Flask dev server (app.run())Observed Behavior:
/healthresponded instantlypage.goto("/")timed out at 30 secondsRoot Cause:
<script>tags/healthbut got stuck queueing asset requestsFix:
threads=16channel_timeout=10Problem 2: Waitress thread exhaustion between test sessions
Observed Behavior:
Root Cause:
Fix:
threads=16channel_timeout=10(from 120)Problem 3: CDN resources blocking DOMContentLoaded
Observed Behavior:
wait_until="domcontentloaded"still caused timeoutsRoot Cause:
<script>downloads + executionindex.htmlcontains 20+ scriptsFix:
Then validate elements using:
to_have_titleto_be_attachedUse independent timeouts (15s–60s) for stability.
Problem 4: SPA routes are unreliable in headless CI
Affected Routes
/#AddCase/#Home/#ConfigRoot Cause
$.load()(AJAX)Fix
Scope tests only to Flask-guaranteed outputs:
/healthAPI/getSessionAPI<title>Evidence: Stable Test Runs (Python 3.12, Windows)
Tests Included
test_health_endpoint→/healthreturns{ "status": "ok" }test_session_api→/getSessionreturns session datatest_load_app[chromium]→ page title matches MUIO 5.5test_static_footer[chromium]→ footer contains MUIO ver.5.5Files Changed
API/app.py/healthendpointui_tests/conftest.pylive_serverfixture using Waitressui_tests/test_ui_smoke.py.github/workflows/ci.ymlui-testjobREADME.mdDependency Hygiene
pytest-playwright and Chromium
Production Environment