-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-ui
executable file
·96 lines (86 loc) · 3.29 KB
/
test-ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# Don't use 'set -e' here as we want to handle errors manually
# Set up variables
SERVER_PID=""
SERVER_STARTED=false
# Function to clean up resources on exit
cleanup() {
# Kill the server if we started it
if [ "$SERVER_STARTED" = true ] && [ ! -z "$SERVER_PID" ]; then
echo "Stopping web server (PID: $SERVER_PID)..."
kill $SERVER_PID
wait $SERVER_PID 2>/dev/null || true
echo "Web server stopped."
fi
exit ${1:-0}
}
# Set up trap for clean exit
trap 'cleanup' EXIT
trap 'cleanup 1' INT TERM
# Check if the server is already running
if ! curl -s http://localhost:8000 > /dev/null; then
echo "Starting web server..."
# Ensure web server log directory exists
mkdir -p /tmp
echo "$(date): Starting web server with command: uv run web/main.py" > /tmp/web-server.log
# Run web server with verbose output and check if it starts successfully
(uv run web/main.py >> /tmp/web-server.log 2>&1) &
SERVER_PID=$!
echo "Server started with PID: $SERVER_PID" >> /tmp/web-server.log
SERVER_STARTED=true
# Wait a moment to catch immediate failures
sleep 1
if ! ps -p $SERVER_PID > /dev/null; then
echo "ERROR: Web server process died immediately after starting"
echo "=== WEB SERVER LOG ==="
cat /tmp/web-server.log
echo "====================="
cleanup 1
fi
# Wait for server to start (up to 25 seconds)
for i in {1..50}; do
if curl -s http://localhost:8000 > /dev/null; then
echo "Web server started successfully."
break
fi
if [ $i -eq 50 ]; then
echo "ERROR: Web server failed to start in time."
echo "=== WEB SERVER LOG ==="
cat /tmp/web-server.log || echo "Could not read web server log"
echo "====================="
echo "INFO: Checking server process status..."
ps -p $SERVER_PID || echo "Server process not found"
echo "INFO: Checking available memory..."
free -h || echo "Memory info not available"
echo "INFO: Checking Python version..."
python --version || echo "Python version check failed"
echo "INFO: Checking uv version..."
uv --version || echo "uv version check failed"
cleanup 1
fi
echo "Waiting for server to start... ($i/50)"
sleep 0.5
done
else
echo "Using existing web server."
fi
# Default to all browsers if none specified
if [ -z "$1" ]; then
echo "Running playwright tests on all browsers"
echo "Supported browsers: chromium, firefox, webkit (Safari engine)"
# Run tests for each browser using multiple --browser arguments
# Add optimization flags: use xvfb for virtual display and run in parallel mode
uv run pytest tests/playwright -v --browser=chromium --browser=firefox --browser=webkit -xvs
TEST_EXIT_CODE=$?
else
# Run with specified browser
echo "Running playwright tests with browser: $1"
echo "Supported browsers: chromium, firefox, webkit (Safari engine)"
uv run pytest tests/playwright -v --browser=$1 -xvs
TEST_EXIT_CODE=$?
fi
# Exit with the test exit code
if [ $TEST_EXIT_CODE -ne 0 ]; then
echo "ERROR: One or more browser tests failed with exit code: $TEST_EXIT_CODE"
exit $TEST_EXIT_CODE
fi