211 lines
5.2 KiB
Bash
Executable File
211 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# E2E Test Runner Script
|
|
# Quick helper for running Playwright E2E tests
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Default values
|
|
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
MODE="all"
|
|
HEADED=false
|
|
DEBUG=false
|
|
UI=false
|
|
WORKERS=1
|
|
GREP=""
|
|
|
|
# Help function
|
|
show_help() {
|
|
cat << EOF
|
|
E2E Test Runner
|
|
|
|
Usage: ./e2e-run.sh [OPTIONS]
|
|
|
|
Options:
|
|
-a, --all Run all tests (default)
|
|
-u, --ui Run with Playwright UI
|
|
-d, --debug Run in debug mode
|
|
-h, --headed Run in headed mode (show browser)
|
|
-g, --grep PATTERN Run tests matching pattern
|
|
-w, --workers N Number of workers (default: 1)
|
|
--auth Run auth tests only
|
|
--landlord Run landlord tests only
|
|
--tenant Run tenant tests only
|
|
--error Run error handling tests only
|
|
--help Show this help message
|
|
|
|
Examples:
|
|
./e2e-run.sh # Run all tests
|
|
./e2e-run.sh --ui # Run with UI
|
|
./e2e-run.sh --grep "login" # Run login tests
|
|
./e2e-run.sh --headed --debug # Run with browser and debugger
|
|
./e2e-run.sh --auth # Run auth tests only
|
|
|
|
Environment Variables:
|
|
PORT Server port (default: 8080)
|
|
E2E_BASE_URL Base URL for tests (default: http://127.0.0.1:8080)
|
|
|
|
EOF
|
|
}
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-a|--all)
|
|
MODE="all"
|
|
shift
|
|
;;
|
|
-u|--ui)
|
|
UI=true
|
|
shift
|
|
;;
|
|
-d|--debug)
|
|
DEBUG=true
|
|
shift
|
|
;;
|
|
-h|--headed)
|
|
HEADED=true
|
|
shift
|
|
;;
|
|
-g|--grep)
|
|
GREP="$2"
|
|
shift 2
|
|
;;
|
|
-w|--workers)
|
|
WORKERS="$2"
|
|
shift 2
|
|
;;
|
|
--auth)
|
|
MODE="auth"
|
|
shift
|
|
;;
|
|
--landlord)
|
|
MODE="landlord"
|
|
shift
|
|
;;
|
|
--tenant)
|
|
MODE="tenant"
|
|
shift
|
|
;;
|
|
--error)
|
|
MODE="error"
|
|
shift
|
|
;;
|
|
--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown option: $1${NC}"
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Change to project directory
|
|
cd "$PROJECT_DIR" || exit 1
|
|
|
|
# Set environment variables
|
|
export PORT="${PORT:-8080}"
|
|
export E2E_BASE_URL="${E2E_BASE_URL:-http://127.0.0.1:8080}"
|
|
|
|
echo -e "${GREEN}╔════════════════════════════════════════════════╗${NC}"
|
|
echo -e "${GREEN}║ Cyber Hybrid Hub E2E Test Runner ║${NC}"
|
|
echo -e "${GREEN}╚════════════════════════════════════════════════╝${NC}"
|
|
echo ""
|
|
echo "Configuration:"
|
|
echo " Mode: $MODE"
|
|
echo " Base URL: $E2E_BASE_URL"
|
|
echo " Workers: $WORKERS"
|
|
echo " Headed: $HEADED"
|
|
echo " Debug: $DEBUG"
|
|
echo " UI: $UI"
|
|
echo ""
|
|
|
|
# Build test command
|
|
CMD="cd .playwright-mcp && npx playwright test"
|
|
|
|
# Add test directory based on mode
|
|
case $MODE in
|
|
auth)
|
|
CMD="$CMD tests/e2e/auth/"
|
|
echo -e "${YELLOW}Running auth tests only...${NC}"
|
|
;;
|
|
landlord)
|
|
CMD="$CMD tests/e2e/landlord/"
|
|
echo -e "${YELLOW}Running landlord tests only...${NC}"
|
|
;;
|
|
tenant)
|
|
CMD="$CMD tests/e2e/tenant/"
|
|
echo -e "${YELLOW}Running tenant tests only...${NC}"
|
|
;;
|
|
error)
|
|
CMD="$CMD tests/e2e/error-handling/"
|
|
echo -e "${YELLOW}Running error handling tests only...${NC}"
|
|
;;
|
|
all)
|
|
echo -e "${YELLOW}Running all tests...${NC}"
|
|
;;
|
|
esac
|
|
|
|
# Add options
|
|
if [ "$UI" = true ]; then
|
|
CMD="$CMD --ui"
|
|
echo -e "${GREEN}📺 Opening Playwright UI...${NC}"
|
|
elif [ "$DEBUG" = true ]; then
|
|
CMD="$CMD --debug"
|
|
echo -e "${GREEN}🐛 Starting debug mode...${NC}"
|
|
else
|
|
# Add reporter
|
|
CMD="$CMD --reporter=list"
|
|
fi
|
|
|
|
if [ "$HEADED" = true ] && [ "$UI" = false ]; then
|
|
CMD="$CMD --headed"
|
|
echo -e "${GREEN}👀 Running in headed mode...${NC}"
|
|
fi
|
|
|
|
if [ -n "$GREP" ]; then
|
|
CMD="$CMD --grep \"$GREP\""
|
|
echo -e "${GREEN}🔍 Filtering by pattern: $GREP${NC}"
|
|
fi
|
|
|
|
if [ "$WORKERS" -gt 1 ]; then
|
|
CMD="$CMD --workers=$WORKERS"
|
|
echo -e "${GREEN}⚡ Using $WORKERS workers${NC}"
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}─────────────────────────────────────────────────────${NC}"
|
|
echo ""
|
|
|
|
# Run command
|
|
eval $CMD
|
|
|
|
# Exit with appropriate code
|
|
EXIT_CODE=$?
|
|
|
|
echo ""
|
|
if [ $EXIT_CODE -eq 0 ]; then
|
|
echo -e "${GREEN}✓ All tests passed!${NC}"
|
|
echo ""
|
|
echo "View HTML report:"
|
|
echo " npx playwright show-report"
|
|
else
|
|
echo -e "${RED}✗ Some tests failed${NC}"
|
|
echo ""
|
|
echo "View results:"
|
|
echo " npx playwright show-report"
|
|
echo ""
|
|
echo "Debug failed tests:"
|
|
echo " npx playwright test --debug"
|
|
fi
|
|
|
|
exit $EXIT_CODE
|