Spaces:
Runtime error
Runtime error
File size: 1,495 Bytes
9dbf2cc d4167d9 9dbf2cc d4167d9 9dbf2cc d4167d9 9dbf2cc d4167d9 9dbf2cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
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() |