handwriting-ocr / test_e2e.py
Raymond Weitekamp
refactor: remove logged-in e2e test for local development - Remove test_page_loads_logged_in test since OAuth features are mocked in local dev - Keep test_page_loads_logged_out for basic page load verification
9dbf2cc
raw
history blame
1.5 kB
import os
import pytest
import pytest_asyncio
from playwright.async_api import async_playwright, expect
import asyncio
# Constants
GRADIO_PORTS = [7861, 7862] # Try both possible ports
@pytest_asyncio.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for each test case."""
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()
@pytest_asyncio.fixture
async def page():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch()
page = await browser.new_page()
yield page
await browser.close()
async def try_connect(page, port):
try:
url = f"http://localhost:{port}"
await page.goto(url)
await page.wait_for_load_state("networkidle", timeout=5000)
return True
except:
return False
@pytest.mark.asyncio
async def test_page_loads_logged_out(page):
connected = False
for port in GRADIO_PORTS:
if await try_connect(page, port):
connected = True
break
assert connected, f"Could not connect to Gradio on any of these ports: {GRADIO_PORTS}"
# Check if the main heading is visible
await expect(page.locator("h2", has_text="Crowdsourcing Handwriting OCR Dataset")).to_be_visible()
# Check for a log-in prompt
await expect(page.locator("text=Please log in with your Hugging Face account")).to_be_visible()