|
|
"""
|
|
|
Test configuration with environment detection for browser automation testing.
|
|
|
Supports both local development and HuggingFace Spaces deployment.
|
|
|
"""
|
|
|
import os
|
|
|
from typing import Optional
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
class TestConfig:
|
|
|
"""Configuration for browser automation tests"""
|
|
|
base_url: str
|
|
|
websocket_url: Optional[str]
|
|
|
environment: str
|
|
|
websocket_enabled: bool
|
|
|
timeout_page_load: int = 30
|
|
|
timeout_action: int = 10
|
|
|
retry_attempts: int = 3
|
|
|
retry_delay: int = 2
|
|
|
screenshot_on_error: bool = True
|
|
|
|
|
|
|
|
|
def detect_environment() -> TestConfig:
|
|
|
"""
|
|
|
Auto-detect environment and return appropriate configuration.
|
|
|
|
|
|
Returns:
|
|
|
TestConfig: Configuration object with environment-specific settings
|
|
|
"""
|
|
|
|
|
|
is_hf = os.getenv('HF_SPACES') == 'true' or os.getenv('SPACE_ID') is not None
|
|
|
|
|
|
|
|
|
base_url_override = os.getenv('BASE_URL')
|
|
|
|
|
|
if is_hf or (base_url_override and 'huggingface.co' in base_url_override):
|
|
|
|
|
|
base_url = base_url_override or 'https://huggingface.co/spaces/Really-amin/Datasourceforcryptocurrency-2'
|
|
|
return TestConfig(
|
|
|
base_url=base_url,
|
|
|
websocket_url=None,
|
|
|
environment='huggingface',
|
|
|
websocket_enabled=False
|
|
|
)
|
|
|
else:
|
|
|
|
|
|
base_url = base_url_override or 'http://localhost:7860'
|
|
|
ws_protocol = 'wss' if 'https' in base_url else 'ws'
|
|
|
ws_host = base_url.replace('http://', '').replace('https://', '')
|
|
|
|
|
|
return TestConfig(
|
|
|
base_url=base_url,
|
|
|
websocket_url=f'{ws_protocol}://{ws_host}/ws',
|
|
|
environment='local',
|
|
|
websocket_enabled=True
|
|
|
)
|
|
|
|
|
|
|
|
|
def get_config() -> TestConfig:
|
|
|
"""Get the current test configuration"""
|
|
|
return detect_environment()
|
|
|
|
|
|
|