diff --git a/tests/test_generate_form.py b/tests/test_generate_form.py index 718d3dc..cf3cd53 100644 --- a/tests/test_generate_form.py +++ b/tests/test_generate_form.py @@ -343,52 +343,54 @@ class TestGenerateFormGooglePlaywright: "Chromium is required for form Playwright tests. " "Run: playwright install --with-deps chromium" ) from exc - page = browser.new_page() - page.add_init_script( - """window.google = { - accounts: { - id: { - initialize() {}, - renderButton() {}, - disableAutoSelect() {}, - }, - }, - };""" - ) - page.route( - "https://accounts.google.com/gsi/client", - lambda route: route.abort(), - ) + try: + page = browser.new_page() + page.add_init_script( + """window.google = { + accounts: { + id: { + initialize() {}, + renderButton() {}, + disableAutoSelect() {}, + }, + }, + };""" + ) + page.route( + "https://accounts.google.com/gsi/client", + lambda route: route.abort(), + ) - def handle_api(route): - if "/api/form-status/" in route.request.url: - route.fulfill( - status=200, - content_type="application/json", - body='{"status":"open"}', - ) - elif "/api/admin/orders" in route.request.url: - route.fulfill( - status=200, - content_type="application/json", - body='{"weeks":["2026-W30"]}', - ) - else: - route.fulfill( - status=404, - content_type="application/json", - body="{}", - ) + def handle_api(route): + if "/api/form-status/" in route.request.url: + route.fulfill( + status=200, + content_type="application/json", + body='{"status":"open"}', + ) + elif "/api/admin/orders" in route.request.url: + route.fulfill( + status=200, + content_type="application/json", + body='{"weeks":["2026-W30"]}', + ) + else: + route.fulfill( + status=404, + content_type="application/json", + body="{}", + ) - page.route("https://api.example.com/**", handle_api) - page.goto(out.as_uri(), wait_until="domcontentloaded") - page.evaluate( - "(credential) => handleCredentialResponse({ credential })", - _google_credential(), - ) - page.locator("#admin-btn").wait_for(state="visible") - yield page - browser.close() + page.route("https://api.example.com/**", handle_api) + page.goto(out.as_uri(), wait_until="domcontentloaded") + page.evaluate( + "(credential) => handleCredentialResponse({ credential })", + _google_credential(), + ) + page.locator("#admin-btn").wait_for(state="visible") + yield page + finally: + browser.close() @pytest.mark.parametrize("width", [320, 375]) def test_signed_in_admin_user_bar_fits_phone_width(