mirror of
https://github.com/johndoe6345789/AutoMetabuilder.git
synced 2026-04-24 13:54:59 +00:00
Add Web UI testing framework: Introduce Playwright for UI tests, add test cases, and server fixture for mock server setup. Update README with testing instructions.
This commit is contained in:
16
README.md
16
README.md
@@ -22,3 +22,19 @@ Run the tool using poetry:
|
||||
```bash
|
||||
poetry run autometabuilder
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
To run the unit tests:
|
||||
```bash
|
||||
PYTHONPATH=src pytest tests/test_main.py tests/test_metadata.py tests/test_roadmap.py
|
||||
```
|
||||
|
||||
To run the Web UI tests (Playwright):
|
||||
```bash
|
||||
# First install browsers if you haven't already
|
||||
playwright install chromium
|
||||
|
||||
# Run the UI tests
|
||||
PYTHONPATH=src pytest tests/ui
|
||||
```
|
||||
|
||||
@@ -21,3 +21,7 @@ messages:
|
||||
listing upcoming work. Ensure all changes are tested, linted, and
|
||||
properly documented. Update ROADMAP.md as you complete tasks.
|
||||
model: openai/gpt-4o
|
||||
|
||||
# Test Comment
|
||||
# Test Comment
|
||||
# Test Comment
|
||||
@@ -73,8 +73,12 @@ def get_env_vars():
|
||||
|
||||
env_vars = {}
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if "=" in line and not line.startswith("#"):
|
||||
key, value = line.strip().split("=", 1)
|
||||
key, value = line.split("=", 1)
|
||||
# Remove quotes if present
|
||||
if (value.startswith("'") and value.endswith("'")) or (value.startswith('"') and value.endswith('"')):
|
||||
value = value[1:-1]
|
||||
env_vars[key] = value
|
||||
return env_vars
|
||||
|
||||
|
||||
21
tests/ui/conftest.py
Normal file
21
tests/ui/conftest.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
import time
|
||||
import multiprocessing
|
||||
import pytest
|
||||
import uvicorn
|
||||
from autometabuilder.web.server import app
|
||||
|
||||
def run_server():
|
||||
os.environ["MOCK_WEB_UI"] = "true"
|
||||
os.environ["WEB_USER"] = "testuser"
|
||||
os.environ["WEB_PASSWORD"] = "testpass"
|
||||
uvicorn.run(app, host="127.0.0.1", port=8001, log_level="error")
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def server():
|
||||
proc = multiprocessing.Process(target=run_server, daemon=True)
|
||||
proc.start()
|
||||
# Give the server a moment to start
|
||||
time.sleep(2)
|
||||
yield "http://127.0.0.1:8001"
|
||||
proc.terminate()
|
||||
67
tests/ui/test_web_ui.py
Normal file
67
tests/ui/test_web_ui.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
from playwright.sync_api import Page, expect
|
||||
|
||||
def test_login_and_dashboard(page: Page, server: str):
|
||||
# Go to the server
|
||||
page.goto(server)
|
||||
|
||||
# We should be prompted for basic auth
|
||||
# Playwright handles basic auth via context or by encoding it in the URL
|
||||
# or we can use the page.authenticate method
|
||||
|
||||
# Alternative: use URL with credentials
|
||||
auth_url = server.replace("http://", "http://testuser:testpass@")
|
||||
page.goto(auth_url)
|
||||
|
||||
# Check if we are on the dashboard
|
||||
expect(page.locator("h1")).to_contain_text("AutoMetabuilder Dashboard")
|
||||
expect(page.locator("text=Logged in as: testuser")).to_be_visible()
|
||||
|
||||
def test_run_bot_mock(page: Page, server: str):
|
||||
auth_url = server.replace("http://", "http://testuser:testpass@")
|
||||
page.goto(auth_url)
|
||||
|
||||
# Click run button
|
||||
page.click("button:has-text('Run Bot')")
|
||||
|
||||
# Status should change to "Bot Running..."
|
||||
expect(page.locator(".badge.bg-warning")).to_contain_text("Bot Running")
|
||||
|
||||
# Wait for it to finish (mock takes 5 seconds)
|
||||
page.wait_for_timeout(6000)
|
||||
|
||||
# Refresh
|
||||
page.reload()
|
||||
expect(page.locator(".badge.bg-success")).to_contain_text("Idle")
|
||||
|
||||
def test_update_prompt(page: Page, server: str):
|
||||
auth_url = server.replace("http://", "http://testuser:testpass@")
|
||||
page.goto(auth_url)
|
||||
|
||||
# Find prompt textarea
|
||||
textarea = page.locator("textarea[name='content']").first
|
||||
original_content = textarea.input_value()
|
||||
|
||||
new_content = original_content + "\n# Test Comment"
|
||||
textarea.fill(new_content)
|
||||
|
||||
# Click update prompt
|
||||
page.click("button:has-text('Save Prompt')")
|
||||
|
||||
# Verify it updated
|
||||
page.reload()
|
||||
expect(page.locator("textarea[name='content']").first).to_have_value(new_content)
|
||||
|
||||
def test_update_settings(page: Page, server: str):
|
||||
auth_url = server.replace("http://", "http://testuser:testpass@")
|
||||
page.goto(auth_url)
|
||||
|
||||
# Add a new setting
|
||||
page.fill("input[name='new_env_key']", "TEST_SETTING")
|
||||
page.fill("input[name='new_env_value']", "test_value")
|
||||
|
||||
page.click("button:has-text('Save Settings')")
|
||||
|
||||
# Verify it appeared in the table
|
||||
page.reload()
|
||||
expect(page.locator("input[name='env_TEST_SETTING']")).to_have_value("test_value")
|
||||
Reference in New Issue
Block a user