SIDEL_ScriptsManager/test_hammer_browser.py

92 lines
2.6 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify the hammer simulator opens in browser automatically
"""
import subprocess
import sys
import os
import tempfile
import time
def test_hammer_simulator():
"""Test the hammer simulator with browser opening"""
# Create a temporary data directory
with tempfile.TemporaryDirectory() as temp_dir:
script_path = os.path.join(
"app", "backend", "script_groups", "hammer", "hammer_simulator.py"
)
if not os.path.exists(script_path):
print(f"Error: Script not found at {script_path}")
return False
# Prepare arguments
args = [
sys.executable,
script_path,
"--data-dir",
temp_dir,
"--user-level",
"operator",
"--port",
"5555",
"--project-id",
"test_project",
]
print("Starting hammer simulator...")
print(f"Command: {' '.join(args)}")
print(f"Data directory: {temp_dir}")
print("This should open a browser tab automatically...")
try:
# Start the process
process = subprocess.Popen(
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
)
# Wait a bit for startup
time.sleep(3)
# Check if process is still running
if process.poll() is None:
print("✅ Process started successfully!")
print("🌐 Browser tab should have opened at: http://127.0.0.1:5555")
print("⏰ Waiting 10 seconds before terminating...")
time.sleep(10)
# Terminate the process
process.terminate()
process.wait(timeout=5)
print("✅ Process terminated cleanly")
return True
else:
stdout, stderr = process.communicate()
print("❌ Process failed to start")
print(f"Return code: {process.returncode}")
print(f"STDOUT: {stdout}")
print(f"STDERR: {stderr}")
return False
except Exception as e:
print(f"❌ Error running process: {e}")
return False
if __name__ == "__main__":
print("=" * 60)
print("Testing Hammer Simulator Browser Opening")
print("=" * 60)
success = test_hammer_simulator()
if success:
print("\n✅ Test completed successfully!")
else:
print("\n❌ Test failed!")
sys.exit(1)