Spaces:
Running
Running
File size: 4,370 Bytes
60b6623 d0a53cb 60b6623 4f2f855 60b6623 d0a53cb 60b6623 4f2f855 60b6623 d0a53cb 60b6623 4e77c80 60b6623 4e77c80 60b6623 4e77c80 60b6623 4e77c80 60b6623 d0a53cb 60b6623 4f2f855 60b6623 |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
import pytest
import requests
import time
import os
# Try to import playwright, but don't fail if not available
try:
from playwright.sync_api import sync_playwright
PLAYWRIGHT_AVAILABLE = True
except ImportError:
PLAYWRIGHT_AVAILABLE = False
# Create test-results directories
os.makedirs("./test-results/videos/", exist_ok=True)
os.makedirs("./test-results/har/", exist_ok=True)
def pytest_configure(config):
"""Configure pytest for E2E tests"""
config.addinivalue_line(
"markers", "e2e: marks tests as end-to-end tests"
)
config.addinivalue_line(
"markers", "upload: marks tests related to upload functionality"
)
config.addinivalue_line(
"markers", "admin: marks tests related to admin functionality"
)
config.addinivalue_line(
"markers", "export: marks tests related to export functionality"
)
@pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
"""Configure browser context for E2E tests"""
if not PLAYWRIGHT_AVAILABLE:
pytest.skip("Playwright not available")
return {
**browser_context_args,
"viewport": {
"width": 1920,
"height": 1080,
},
"ignore_https_errors": True,
"record_video_dir": "./test-results/videos/",
"record_har_path": "./test-results/har/test.har",
}
@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
"""Configure browser launch arguments"""
if not PLAYWRIGHT_AVAILABLE:
pytest.skip("Playwright not available")
return {
**browser_type_launch_args,
"args": [
"--disable-web-security",
"--disable-features=VizDisplayCompositor",
"--no-sandbox",
"--disable-setuid-sandbox",
]
}
@pytest.fixture(scope="session")
def wait_for_services():
"""Wait for all services to be ready before running tests"""
print("Waiting for services to be ready...")
# Wait for backend
backend_ready = False
for i in range(30): # Wait up to 30 seconds
try:
response = requests.get("http://localhost:7860/health", timeout=5)
if response.status_code == 200:
backend_ready = True
print("Backend is ready")
break
except requests.exceptions.RequestException:
pass
time.sleep(1)
if not backend_ready:
pytest.fail("Backend service is not ready")
# Wait for application (frontend served by backend)
app_ready = False
for i in range(30): # Wait up to 30 seconds
try:
response = requests.get("http://localhost:7860", timeout=5)
if response.status_code == 200:
app_ready = True
print("Application is ready")
break
except requests.exceptions.RequestException:
pass
time.sleep(1)
if not app_ready:
pytest.fail("Application service is not ready")
print("All services are ready!")
@pytest.fixture(scope="function")
def reset_test_data():
"""Reset test data between tests"""
try:
# Call the test reset endpoint if available
response = requests.post("http://localhost:7860/test/reset", timeout=10)
if response.status_code == 200:
print("Test data reset successful")
else:
print("Test data reset failed, continuing anyway")
except requests.exceptions.RequestException:
print("Test reset endpoint not available, continuing anyway")
yield
@pytest.fixture(scope="function")
def page(page, wait_for_services, reset_test_data):
"""Configure page for E2E tests"""
if not PLAYWRIGHT_AVAILABLE:
pytest.skip("Playwright not available")
# Set up page with proper viewport and other settings
page.set_viewport_size({"width": 1920, "height": 1080})
yield page
# Video recording is handled automatically by Playwright
# No manual start/stop needed
def pytest_runtest_setup(item):
"""Setup before each test"""
# Ensure we're in the e2e directory
os.chdir(os.path.dirname(__file__))
def pytest_runtest_teardown(item, nextitem):
"""Teardown after each test"""
# Any cleanup needed after tests
pass
|