Raymond Weitekamp commited on
Commit
9dbf2cc
·
1 Parent(s): 7e41e14

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

Browse files
Files changed (1) hide show
  1. test_e2e.py +44 -8
test_e2e.py CHANGED
@@ -1,13 +1,49 @@
 
1
  import pytest
2
- from playwright.sync_api import expect
 
 
3
 
4
  # Constants
5
- GRADIO_PORT = 7861
6
- GRADIO_URL = f"http://localhost:{GRADIO_PORT}"
7
 
8
- def test_page_loads(page):
9
- page.goto(GRADIO_URL)
10
- page.wait_for_load_state("networkidle")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # Check if title is present with exact text
13
- expect(page.locator("h2", has_text="Crowdsourcing Handwriting OCR Dataset")).to_be_visible()
 
1
+ import os
2
  import pytest
3
+ import pytest_asyncio
4
+ from playwright.async_api import async_playwright, expect
5
+ import asyncio
6
 
7
  # Constants
8
+ GRADIO_PORTS = [7861, 7862] # Try both possible ports
 
9
 
10
+ @pytest_asyncio.fixture(scope="session")
11
+ def event_loop():
12
+ """Create an instance of the default event loop for each test case."""
13
+ policy = asyncio.get_event_loop_policy()
14
+ loop = policy.new_event_loop()
15
+ yield loop
16
+ loop.close()
17
+
18
+ @pytest_asyncio.fixture
19
+ async def page():
20
+ async with async_playwright() as playwright:
21
+ browser = await playwright.chromium.launch()
22
+ page = await browser.new_page()
23
+ yield page
24
+ await browser.close()
25
+
26
+ async def try_connect(page, port):
27
+ try:
28
+ url = f"http://localhost:{port}"
29
+ await page.goto(url)
30
+ await page.wait_for_load_state("networkidle", timeout=5000)
31
+ return True
32
+ except:
33
+ return False
34
+
35
+ @pytest.mark.asyncio
36
+ async def test_page_loads_logged_out(page):
37
+ connected = False
38
+ for port in GRADIO_PORTS:
39
+ if await try_connect(page, port):
40
+ connected = True
41
+ break
42
+
43
+ assert connected, f"Could not connect to Gradio on any of these ports: {GRADIO_PORTS}"
44
+
45
+ # Check if the main heading is visible
46
+ await expect(page.locator("h2", has_text="Crowdsourcing Handwriting OCR Dataset")).to_be_visible()
47
 
48
+ # Check for a log-in prompt
49
+ await expect(page.locator("text=Please log in with your Hugging Face account")).to_be_visible()