39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
# test_playwright_visual.py
|
|
import sys
|
|
import subprocess
|
|
import time
|
|
import os
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
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")
|
|
|
|
# Take a screenshot of the page
|
|
screenshot_path = "test/screenshot.png"
|
|
page.screenshot(path=screenshot_path)
|
|
print(f"Playwright visual test PASSED: Screenshot saved to {screenshot_path}")
|
|
|
|
browser.close()
|
|
finally:
|
|
app_process.terminate()
|
|
|
|
if __name__ == "__main__":
|
|
run_test() |