File size: 2,585 Bytes
21b071a 046548a 461547b 046548a 21b071a 046548a 461547b 046548a 461547b 1004adf 046548a 1004adf 046548a 461547b 046548a 1004adf 046548a 1004adf 046548a | 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | """Playwright headless smoke test.
Boots ``app.py`` in a subprocess (via the ``app_url`` fixture in
:mod:`conftest`) and asserts the Phase D minimum:
- All three Gradio tabs render.
- The Detailed View tab carries two stacked ``Leaderboard`` widgets
(Validated + Unvalidated, per the two-tier viewer landed in C3).
If the Space won't load these tabs or the leaderboards don't render,
every other test downstream is meaningless.
Requires:
- ``pip install -r requirements-dev.txt``
- ``playwright install chromium`` (one-off, fetches the bundled browser)
"""
from __future__ import annotations
from playwright.sync_api import expect, sync_playwright
def test_three_tabs_render(app_url):
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
try:
page = browser.new_page()
page.goto(app_url)
for tab_name in ("Leaderboard", "Submit", "About"):
expect(page.get_by_role("tab", name=tab_name)).to_be_visible(
timeout=15_000
)
finally:
browser.close()
def test_two_leaderboard_widgets_render(app_url):
"""Both Validated and Unvalidated leaderboards render on the Detailed View tab.
The Leaderboard (visual) tab is the default (first) tab, so the
Detailed View tab's content is mounted-but-hidden until selected;
click the tab first, then
assert. The two widgets are identified by their labels (set in
app.py). The labels are case-sensitive substrings that don't overlap
("Validated Leaderboard" is not a substring of "Unvalidated
Leaderboard" with the uppercase V).
The ``Leaderboard`` widget renders each label twice: the visible
``<p>`` label and a screen-reader-only ``<caption class="sr-only">``
inside the table. Both match the text, so the locator is scoped to
the ``<p>`` label to avoid a strict-mode "resolved to 2 elements"
violation.
"""
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
try:
page = browser.new_page()
page.goto(app_url)
page.get_by_role("tab", name="Detailed View").click()
expect(
page.get_by_text("Validated Leaderboard", exact=True)
.and_(page.locator("p"))
).to_be_visible(timeout=15_000)
expect(
page.get_by_text("Unvalidated Leaderboard", exact=True)
.and_(page.locator("p"))
).to_be_visible(timeout=15_000)
finally:
browser.close()
|