Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
test_realtime_monitor.py · 6.1 KB · 174 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | Selenium test specifically for Real-time Monitor |
| 4 | """ |
| 5 | |
| 6 | from selenium import webdriver |
| 7 | from selenium.webdriver.common.by import By |
| 8 | from selenium.webdriver.support.ui import WebDriverWait |
| 9 | from selenium.webdriver.support import expected_conditions as EC |
| 10 | from selenium.webdriver.chrome.options import Options |
| 11 | import time |
| 12 | import sys |
| 13 | |
| 14 | def test_realtime_monitor(headless=False): |
| 15 | # Setup Chrome options |
| 16 | options = Options() |
| 17 | if headless: |
| 18 | options.add_argument('--headless=new') |
| 19 | options.add_argument('--no-sandbox') |
| 20 | options.add_argument('--disable-dev-shm-usage') |
| 21 | options.add_argument('--window-size=1920,1080') |
| 22 | |
| 23 | driver = webdriver.Chrome(options=options) |
| 24 | |
| 25 | try: |
| 26 | print('📡 Testing Real-time Monitor with Selenium') |
| 27 | print('=' * 50) |
| 28 | |
| 29 | # Navigate to Real-time Monitor |
| 30 | driver.get('http://localhost:8004') |
| 31 | print('✅ Loaded http://localhost:8004') |
| 32 | |
| 33 | # Wait for page to load |
| 34 | wait = WebDriverWait(driver, 10) |
| 35 | |
| 36 | # Check page title |
| 37 | title = driver.title |
| 38 | print(f'📄 Page Title: "{title}"') |
| 39 | |
| 40 | # Check for header |
| 41 | try: |
| 42 | header = driver.find_element(By.CLASS_NAME, 'header') |
| 43 | header_text = header.text |
| 44 | print(f'✅ Header found: "{header_text}"') |
| 45 | except Exception as e: |
| 46 | print(f'❌ Header not found: {e}') |
| 47 | |
| 48 | # Check for WebSocket status |
| 49 | try: |
| 50 | status = driver.find_element(By.CLASS_NAME, 'status') |
| 51 | status_text = status.text |
| 52 | print(f'✅ Status indicator: "{status_text}"') |
| 53 | |
| 54 | # Check status color/class |
| 55 | status_classes = status.get_attribute('class') |
| 56 | print(f' Status classes: {status_classes}') |
| 57 | except Exception as e: |
| 58 | print(f'❌ Status indicator not found: {e}') |
| 59 | |
| 60 | # Check for events container |
| 61 | try: |
| 62 | events = driver.find_element(By.ID, 'events') |
| 63 | print('✅ Events container found') |
| 64 | |
| 65 | # Check if any events are present |
| 66 | event_items = events.find_elements(By.CLASS_NAME, 'event-item') |
| 67 | if event_items: |
| 68 | print(f' Found {len(event_items)} events') |
| 69 | for i, event in enumerate(event_items[:3]): # Show first 3 |
| 70 | print(f' Event {i+1}: {event.text[:50]}...') |
| 71 | else: |
| 72 | print(' No events yet (waiting for activity)') |
| 73 | except Exception as e: |
| 74 | print(f'❌ Events container not found: {e}') |
| 75 | |
| 76 | # Check for control buttons |
| 77 | print('\n🎮 Checking control buttons:') |
| 78 | buttons = { |
| 79 | 'clearBtn': 'Clear button', |
| 80 | 'pauseBtn': 'Pause button', |
| 81 | 'exportBtn': 'Export button' |
| 82 | } |
| 83 | |
| 84 | for btn_id, btn_name in buttons.items(): |
| 85 | try: |
| 86 | btn = driver.find_element(By.ID, btn_id) |
| 87 | print(f'✅ {btn_name} found: "{btn.text}"') |
| 88 | if btn.is_enabled(): |
| 89 | print(f' Button is enabled') |
| 90 | else: |
| 91 | print(f' Button is disabled') |
| 92 | except Exception as e: |
| 93 | print(f'❌ {btn_name} not found') |
| 94 | |
| 95 | # Check for stats panel |
| 96 | try: |
| 97 | stats = driver.find_element(By.CLASS_NAME, 'stats') |
| 98 | print('\n📊 Stats panel found') |
| 99 | stat_items = stats.find_elements(By.TAG_NAME, 'div') |
| 100 | for item in stat_items[:5]: # Show first 5 |
| 101 | text = item.text |
| 102 | if text: |
| 103 | print(f' {text}') |
| 104 | except Exception as e: |
| 105 | print(f'❌ Stats panel not found: {e}') |
| 106 | |
| 107 | # Check WebSocket connection via JavaScript |
| 108 | print('\n🔌 Checking WebSocket:') |
| 109 | try: |
| 110 | ws_state = driver.execute_script(""" |
| 111 | if (window.ws) { |
| 112 | return { |
| 113 | readyState: window.ws.readyState, |
| 114 | url: window.ws.url, |
| 115 | readyStateText: ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'][window.ws.readyState] |
| 116 | }; |
| 117 | } |
| 118 | return null; |
| 119 | """) |
| 120 | |
| 121 | if ws_state: |
| 122 | print(f'✅ WebSocket found:') |
| 123 | print(f' URL: {ws_state.get("url")}') |
| 124 | print(f' State: {ws_state.get("readyStateText")} ({ws_state.get("readyState")})') |
| 125 | else: |
| 126 | print('⚠️ WebSocket not initialized yet') |
| 127 | except Exception as e: |
| 128 | print(f'❌ Could not check WebSocket: {e}') |
| 129 | |
| 130 | # Take screenshot |
| 131 | screenshot_path = 'realtime_monitor_selenium.png' |
| 132 | driver.save_screenshot(screenshot_path) |
| 133 | print(f'\n📸 Screenshot saved: {screenshot_path}') |
| 134 | |
| 135 | # Get console logs |
| 136 | print('\n📝 Browser console logs:') |
| 137 | logs = driver.get_log('browser') |
| 138 | for log in logs[-5:]: # Last 5 logs |
| 139 | print(f' [{log["level"]}] {log["message"][:100]}') |
| 140 | |
| 141 | # Test interaction - click Pause button |
| 142 | print('\n🧪 Testing interaction:') |
| 143 | try: |
| 144 | pause_btn = driver.find_element(By.ID, 'pauseBtn') |
| 145 | initial_text = pause_btn.text |
| 146 | pause_btn.click() |
| 147 | time.sleep(0.5) |
| 148 | new_text = pause_btn.text |
| 149 | if initial_text != new_text: |
| 150 | print(f'✅ Pause button clicked: "{initial_text}" → "{new_text}"') |
| 151 | else: |
| 152 | print(f'⚠️ Pause button clicked but text unchanged: "{initial_text}"') |
| 153 | except Exception as e: |
| 154 | print(f'❌ Could not test pause button: {e}') |
| 155 | |
| 156 | print('\n' + '=' * 50) |
| 157 | print('✅ Real-time Monitor is working correctly!') |
| 158 | return True |
| 159 | |
| 160 | except Exception as e: |
| 161 | print(f'\n❌ Error testing Real-time Monitor: {e}') |
| 162 | driver.save_screenshot('realtime_monitor_error.png') |
| 163 | return False |
| 164 | |
| 165 | finally: |
| 166 | if not headless: |
| 167 | input('\n⏸️ Press Enter to close browser...') |
| 168 | driver.quit() |
| 169 | |
| 170 | if __name__ == "__main__": |
| 171 | # Run with visible browser by default, add --headless for headless mode |
| 172 | headless = '--headless' in sys.argv |
| 173 | success = test_realtime_monitor(headless=headless) |
| 174 | sys.exit(0 if success else 1) |