pupilometer/test/test_playwright_text.py

55 lines
2.0 KiB
Python

# test_playwright_text.py
import sys
import subprocess
import time
import os
from playwright.sync_api import sync_playwright, expect
def run_test():
# Set environment variable for camera debug mode
env = os.environ.copy()
env["CAMERA_DEBUG_MODE"] = "True"
# Use the python from the virtual environment
python_executable = ".venv/bin/python"
# Install dependencies
subprocess.run([python_executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
# Start the application
app_process = subprocess.Popen([python_executable, "src/pupilometerApp/app.py"], env=env)
time.sleep(5) # Wait for the server to start
try:
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("http://localhost:5000")
# Check for the main page title
expect(page).to_have_title("Pupilometer Control")
print("Playwright text test PASSED: Found correct page title.")
# Check for the lamp control panel
expect(page.locator(".left-panel h1")).to_have_text("Lamp Matrix Control")
print("Playwright text test PASSED: Found lamp control panel.")
# Check for the camera feeds panel
expect(page.locator(".right-panel h1")).to_have_text("Camera Feeds")
print("Playwright text test PASSED: Found camera feeds panel.")
# Simulate setting a lamp color to trigger the /set_matrix endpoint
print("Simulating lamp color change to trigger /set_matrix...")
# Click on the first lamp (row 0, col 0)
page.locator('.lamp[data-row="0"][data-col="0"]').click()
print("Clicked on lamp at (0,0). This should trigger /set_matrix.")
# Wait for a potential network request or UI update
page.wait_for_timeout(1000)
browser.close()
finally:
app_process.terminate()
if __name__ == "__main__":
run_test()