#!/bin/bash # Define paths SITE_DIR="/path/to/file" SELENIUM_DIR="$SITE_DIR/tests/selenium" # Function to check if a process is running on port 3001 check_port() { lsof -i:3001 > /dev/null return $? } # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}====================================${NC}" echo -e "${GREEN}AI Resource Pro Testing Script${NC}" echo -e "${BLUE}====================================${NC}" # Navigate to the project root echo -e "${YELLOW}Navigating to project root at $SITE_DIR${NC}" cd "$SITE_DIR" || { echo "Failed to navigate to $SITE_DIR"; exit 1; } # Check if Next.js app is already running if check_port; then echo -e "${GREEN}Next.js app is already running on port 3001${NC}" else echo -e "${YELLOW}Starting Next.js app in a new terminal window...${NC}" # For macOS, use open command to start a new terminal window # This assumes zsh shell, adjust if using a different shell osascript -e 'tell application "Terminal" to do script "cd '"$SITE_DIR"' && npm run dev"' # Wait for Next.js to start (adjust sleep time as needed) echo -e "${YELLOW}Waiting for Next.js to start...${NC}" sleep 10 # Check if Next.js started successfully if check_port; then echo -e "${GREEN}Next.js app started successfully on port 3001${NC}" else echo "Failed to start Next.js app on port 3001" exit 1 fi fi # Navigate to the Selenium tests directory echo -e "${YELLOW}Navigating to Selenium tests directory at $SELENIUM_DIR${NC}" cd "$SELENIUM_DIR" || { echo "Failed to navigate to $SELENIUM_DIR"; exit 1; } # Activate Python virtual environment echo -e "${YELLOW}Activating Python virtual environment...${NC}" if [ -d "venv" ]; then source venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; } echo -e "${GREEN}Virtual environment activated${NC}" else echo "Virtual environment not found at $SELENIUM_DIR/venv" echo "Would you like to create a new virtual environment? (y/n)" read -r create_venv if [ "$create_venv" = "y" ]; then python -m venv venv source venv/bin/activate echo "Installing requirements..." pip install -r requirements.txt else exit 1 fi fi # Run the tests echo -e "${BLUE}====================================${NC}" echo -e "${GREEN}Running Selenium tests...${NC}" echo -e "${BLUE}====================================${NC}" echo "Available test options:" echo "1) Run single test (test_page_loads)" echo "2) Run all AI Coach tests" echo "3) Run all tests" echo "4) Run test_generate_roadmap test" echo "Enter your choice (1-4):" read -r test_choice case $test_choice in 1) echo -e "${YELLOW}Running test_page_loads test...${NC}" python -m pytest -v test_ai_coach.py::TestAICoach::test_page_loads ;; 2) echo -e "${YELLOW}Running all AI Coach tests...${NC}" python -m pytest -v test_ai_coach.py ;; 3) echo -e "${YELLOW}Running all tests...${NC}" python -m pytest -v ;; 4) echo -e "${YELLOW}Running test_generate_roadmap test...${NC}" python -m pytest -v test_ai_coach.py::TestAICoach::test_generate_roadmap ;; *) echo "Invalid choice" exit 1 ;; esac # Check test results test_result=$? if [ $test_result -eq 0 ]; then echo -e "${GREEN}All tests passed successfully!${NC}" else echo -e "${YELLOW}Some tests failed. Check the output above for more details.${NC}" fi echo -e "${BLUE}====================================${NC}" echo -e "${GREEN}Test run complete${NC}" echo -e "${BLUE}====================================${NC}" # Deactivate Python virtual environment deactivate echo "Python virtual environment deactivated" echo "Press Enter to exit..." read -r