#!/usr/bin/env python3 """ Run Selenium test with a temporary LightRAG server. """ import subprocess import time import sys import os import urllib.request import urllib.error def is_server_running(url='http://localhost:8000', timeout=2): try: response = urllib.request.urlopen(url, timeout=timeout) return response.status < 500 except: return False def start_server(): """Start LightRAG server as a subprocess.""" # Change to LightRAG-main directory cwd = os.path.dirname(os.path.abspath(__file__)) env = os.environ.copy() # Ensure Python path includes current directory env['PYTHONPATH'] = cwd + (os.pathsep + env.get('PYTHONPATH', '')) cmd = [sys.executable, 'lightrag_server.py'] proc = subprocess.Popen( cmd, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) return proc def main(): print("Starting LightRAG server...") server_proc = start_server() # Wait for server to be ready max_wait = 30 start_time = time.time() while time.time() - start_time < max_wait: if is_server_running(): print("Server is ready.") break time.sleep(1) else: print("Server failed to start within 30 seconds.") server_proc.terminate() server_proc.wait() sys.exit(1) # Run Selenium test print("Running Selenium test...") from test_workspace_ui_isolation import test_workspace_ui_isolation try: test_workspace_ui_isolation() print("Selenium test completed successfully.") except Exception as e: print(f"Selenium test failed: {e}") server_proc.terminate() server_proc.wait() sys.exit(1) # Stop server print("Stopping server...") server_proc.terminate() server_proc.wait() print("Done.") if __name__ == "__main__": main()