Browser Automation Testing Suite
Comprehensive automated browser testing system for the Crypto Monitor application.
Features
- β Environment Auto-Detection: Automatically detects local vs HuggingFace Spaces
- β Comprehensive Testing: Tests all 16 pages with buttons, forms, and interactions
- β API Testing: Validates all critical API endpoints
- β WebSocket Testing: Tests WebSocket connections (local only)
- β Beautiful Reports: Generates JSON and HTML reports with detailed results
- β Error Handling: Retry logic, screenshots on failure, detailed error messages
Installation
# Install required dependencies
pip install httpx
Usage
Local Testing
# Run all tests
python browser-testing/test_runner.py
# With custom URL
BASE_URL=http://localhost:7860 python browser-testing/test_runner.py
HuggingFace Spaces Testing
# Test HuggingFace Spaces deployment
HF_SPACES=true BASE_URL=https://huggingface.co/spaces/Really-amin/Datasourceforcryptocurrency-2 python browser-testing/test_runner.py
Test Structure
browser-testing/
βββ config.py # Environment detection & configuration
βββ test_runner.py # Main test orchestrator
βββ utils/
β βββ browser_utils.py # Browser automation utilities
β βββ api_tester.py # API endpoint testing
β βββ websocket_tester.py # WebSocket testing (local only)
β βββ report_generator.py # Report generation
βββ page_testers/
βββ base_tester.py # Base class for all page testers
βββ dashboard_tester.py # Dashboard page tests
βββ market_tester.py # Market page tests
βββ ... # 16 page-specific testers
Test Coverage
Pages Tested (16 total)
- Dashboard (
/) - Market (
/market) - Models (
/models) - Sentiment (
/sentiment) - AI Analyst (
/ai-analyst) - Trading Assistant (
/trading-assistant) - News (
/news) - Providers (
/providers) - Diagnostics (
/diagnostics) - API Explorer (
/api-explorer) - Crypto API Hub (
/crypto-api-hub) - Technical Analysis (
/technical-analysis) - Data Sources (
/data-sources) - AI Tools (
/ai-tools) - Help (
/help) - Settings (
/settings)
Test Types
Basic Tests (all pages):
- Page navigation
- Page load completion
- Essential elements present
- No console errors
- Layout components loaded
Page-Specific Tests:
- Button functionality
- Form inputs
- Tab switching
- Data loading
- API interactions
API Tests:
- Health endpoints
- Status endpoints
- Data endpoints
- Response validation
WebSocket Tests (local only):
- Connection establishment
- Message send/receive
- Subscriptions
Reports
Test reports are generated in test-results/:
test-results/
βββ reports/
β βββ report_YYYYMMDD_HHMMSS.json # JSON report
β βββ report_YYYYMMDD_HHMMSS.html # HTML report
β βββ latest.json # Symlink to latest
βββ screenshots/
β βββ *.png # Screenshots on errors
βββ logs/
βββ *.log # Test execution logs
Configuration
Environment variables:
BASE_URL: Override base URL (default: http://localhost:7860)HF_SPACES: Set to 'true' for HuggingFace Spaces modeSPACE_ID: HuggingFace Space ID (auto-detected)
Environment Differences
Local Development
- WebSocket: Enabled
- URL:
http://localhost:7860 - Full feature testing
HuggingFace Spaces
- WebSocket: Disabled (per
.hf_spaces_config) - URL:
https://huggingface.co/spaces/Really-amin/Datasourceforcryptocurrency-2 - HTTP-only testing
Success Criteria
- β All pages load successfully
- β All buttons functional
- β All forms work correctly
- β All tabs switch properly
- β All API calls succeed
- β No console errors
- β Proper styling on all pages
- β WebSocket works (local only)
- β Pass rate >= 90%
Troubleshooting
Server Not Running
Ensure the server is running before tests:
python production_server.py
Import Errors
Make sure you're running from the project root:
cd /path/to/crypto-dt-source-main
python browser-testing/test_runner.py
Permission Errors
Check that test-results directory is writable:
mkdir -p test-results/{reports,screenshots,logs}
chmod -R 755 test-results
Development
To add new tests:
- Create page tester in
page_testers/ - Inherit from
BasePageTester - Implement
run_specific_tests()method - Add to
test_runner.pypage_testers list
Example:
class MyPageTester(BasePageTester):
async def run_specific_tests(self) -> List[TestResult]:
results = []
results.append(await self.test_my_feature())
return results
async def test_my_feature(self) -> TestResult:
# Your test logic here
pass
License
Part of the Crypto Monitor project.