Spaces:
Sleeping
Sleeping
| """ | |
| E2E Tests for Gradio App | |
| Playwright-based tests for the Gradio UI. | |
| These tests require the app to be running on localhost:7860. | |
| """ | |
| from __future__ import annotations | |
| import pytest | |
| # Mark all tests in this module as E2E | |
| pytestmark = [pytest.mark.e2e, pytest.mark.slow] | |
| class TestAppLoading: | |
| """Tests for app loading and initial state.""" | |
| async def test_homepage_loads(self, gradio_url: str) -> None: | |
| """Test that the homepage loads successfully.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| response = await page.goto(gradio_url) | |
| # Check response is successful | |
| assert response is not None | |
| assert response.status == 200 | |
| await browser.close() | |
| async def test_hero_section_visible(self, gradio_url: str) -> None: | |
| """Test that hero section is visible.""" | |
| from playwright.async_api import async_playwright, expect | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| # Look for header/hero content | |
| await page.wait_for_load_state("networkidle") | |
| # Check for key elements (adjust selectors based on actual app) | |
| # await expect(page.locator("h1")).to_be_visible() | |
| await browser.close() | |
| async def test_all_tabs_present(self, gradio_url: str) -> None: | |
| """Test that all 6 tabs are present.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Check for tab buttons (adjust selectors based on actual app) | |
| # tabs = await page.locator("button.tab").count() | |
| # assert tabs >= 6 | |
| await browser.close() | |
| class TestScraperTab: | |
| """Tests for Scraper tab functionality.""" | |
| async def test_url_input_exists(self, gradio_url: str) -> None: | |
| """Test that URL input field exists.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Look for input/textarea elements | |
| # inputs = await page.locator("textarea, input[type='text']").count() | |
| # assert inputs > 0 | |
| await browser.close() | |
| async def test_scrape_button_exists(self, gradio_url: str) -> None: | |
| """Test that scrape button exists.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Look for button with scrape-related text | |
| # scrape_btn = page.locator("button:has-text('Scrape')") | |
| # await expect(scrape_btn).to_be_visible() | |
| await browser.close() | |
| class TestDiscoverTab: | |
| """Tests for Discover tab functionality.""" | |
| async def test_search_input_exists(self, gradio_url: str) -> None: | |
| """Test that search input exists in Discover tab.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Navigate to Discover tab and check for search input | |
| # discover_tab = page.locator("button:has-text('Discover')") | |
| # await discover_tab.click() | |
| await browser.close() | |
| class TestSonicTab: | |
| """Tests for Sonic (TTS) tab functionality.""" | |
| async def test_voice_dropdown_exists(self, gradio_url: str) -> None: | |
| """Test that voice selection dropdown exists.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Navigate to Sonic tab | |
| # Check for voice dropdown | |
| await browser.close() | |
| class TestResponsiveDesign: | |
| """Tests for responsive design across viewports.""" | |
| async def test_mobile_viewport(self, gradio_url: str) -> None: | |
| """Test app renders correctly on mobile viewport.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page(viewport={"width": 375, "height": 667}) | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Verify mobile layout renders | |
| # No horizontal scrollbar | |
| await browser.close() | |
| async def test_tablet_viewport(self, gradio_url: str) -> None: | |
| """Test app renders correctly on tablet viewport.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page(viewport={"width": 768, "height": 1024}) | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| await browser.close() | |
| class TestAccessibility: | |
| """Tests for accessibility compliance.""" | |
| async def test_page_has_title(self, gradio_url: str) -> None: | |
| """Test that page has a title.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| await page.goto(gradio_url) | |
| title = await page.title() | |
| assert title is not None | |
| assert len(title) > 0 | |
| await browser.close() | |
| async def test_no_console_errors(self, gradio_url: str) -> None: | |
| """Test that page loads without console errors.""" | |
| from playwright.async_api import async_playwright | |
| async with async_playwright() as p: | |
| browser = await p.chromium.launch() | |
| page = await browser.new_page() | |
| errors: list[str] = [] | |
| page.on("console", lambda msg: errors.append(msg.text) if msg.type == "error" else None) | |
| await page.goto(gradio_url) | |
| await page.wait_for_load_state("networkidle") | |
| # Some errors might be expected, but check for critical failures | |
| # assert len(errors) == 0 or True # Adjust based on expected behavior | |
| await browser.close() | |