AI Resource Pro / website / tests / selenium / run_tests.sh
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Define paths |
| 4 | SITE_DIR="/path/to/file" |
| 5 | SELENIUM_DIR="$SITE_DIR/tests/selenium" |
| 6 | |
| 7 | # Function to check if a process is running on port 3001 |
| 8 | check_port() { |
| 9 | lsof -i:3001 > /dev/null |
| 10 | return $? |
| 11 | } |
| 12 | |
| 13 | # Colors for output |
| 14 | GREEN='\033[0;32m' |
| 15 | YELLOW='\033[1;33m' |
| 16 | BLUE='\033[0;34m' |
| 17 | NC='\033[0m' # No Color |
| 18 | |
| 19 | echo -e "${BLUE}====================================${NC}" |
| 20 | echo -e "${GREEN}AI Resource Pro Testing Script${NC}" |
| 21 | echo -e "${BLUE}====================================${NC}" |
| 22 | |
| 23 | # Navigate to the project root |
| 24 | echo -e "${YELLOW}Navigating to project root at $SITE_DIR${NC}" |
| 25 | cd "$SITE_DIR" || { echo "Failed to navigate to $SITE_DIR"; exit 1; } |
| 26 | |
| 27 | # Check if Next.js app is already running |
| 28 | if check_port; then |
| 29 | echo -e "${GREEN}Next.js app is already running on port 3001${NC}" |
| 30 | else |
| 31 | echo -e "${YELLOW}Starting Next.js app in a new terminal window...${NC}" |
| 32 | # For macOS, use open command to start a new terminal window |
| 33 | # This assumes zsh shell, adjust if using a different shell |
| 34 | osascript -e 'tell application "Terminal" to do script "cd '"$SITE_DIR"' && npm run dev"' |
| 35 | |
| 36 | # Wait for Next.js to start (adjust sleep time as needed) |
| 37 | echo -e "${YELLOW}Waiting for Next.js to start...${NC}" |
| 38 | sleep 10 |
| 39 | |
| 40 | # Check if Next.js started successfully |
| 41 | if check_port; then |
| 42 | echo -e "${GREEN}Next.js app started successfully on port 3001${NC}" |
| 43 | else |
| 44 | echo "Failed to start Next.js app on port 3001" |
| 45 | exit 1 |
| 46 | fi |
| 47 | fi |
| 48 | |
| 49 | # Navigate to the Selenium tests directory |
| 50 | echo -e "${YELLOW}Navigating to Selenium tests directory at $SELENIUM_DIR${NC}" |
| 51 | cd "$SELENIUM_DIR" || { echo "Failed to navigate to $SELENIUM_DIR"; exit 1; } |
| 52 | |
| 53 | # Activate Python virtual environment |
| 54 | echo -e "${YELLOW}Activating Python virtual environment...${NC}" |
| 55 | if [ -d "venv" ]; then |
| 56 | source venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; } |
| 57 | echo -e "${GREEN}Virtual environment activated${NC}" |
| 58 | else |
| 59 | echo "Virtual environment not found at $SELENIUM_DIR/venv" |
| 60 | echo "Would you like to create a new virtual environment? (y/n)" |
| 61 | read -r create_venv |
| 62 | if [ "$create_venv" = "y" ]; then |
| 63 | python -m venv venv |
| 64 | source venv/bin/activate |
| 65 | echo "Installing requirements..." |
| 66 | pip install -r requirements.txt |
| 67 | else |
| 68 | exit 1 |
| 69 | fi |
| 70 | fi |
| 71 | |
| 72 | # Run the tests |
| 73 | echo -e "${BLUE}====================================${NC}" |
| 74 | echo -e "${GREEN}Running Selenium tests...${NC}" |
| 75 | echo -e "${BLUE}====================================${NC}" |
| 76 | echo "Available test options:" |
| 77 | echo "1) Run single test (test_page_loads)" |
| 78 | echo "2) Run all AI Coach tests" |
| 79 | echo "3) Run all tests" |
| 80 | echo "4) Run test_generate_roadmap test" |
| 81 | echo "Enter your choice (1-4):" |
| 82 | read -r test_choice |
| 83 | |
| 84 | case $test_choice in |
| 85 | 1) |
| 86 | echo -e "${YELLOW}Running test_page_loads test...${NC}" |
| 87 | python -m pytest -v test_ai_coach.py::TestAICoach::test_page_loads |
| 88 | ;; |
| 89 | 2) |
| 90 | echo -e "${YELLOW}Running all AI Coach tests...${NC}" |
| 91 | python -m pytest -v test_ai_coach.py |
| 92 | ;; |
| 93 | 3) |
| 94 | echo -e "${YELLOW}Running all tests...${NC}" |
| 95 | python -m pytest -v |
| 96 | ;; |
| 97 | 4) |
| 98 | echo -e "${YELLOW}Running test_generate_roadmap test...${NC}" |
| 99 | python -m pytest -v test_ai_coach.py::TestAICoach::test_generate_roadmap |
| 100 | ;; |
| 101 | *) |
| 102 | echo "Invalid choice" |
| 103 | exit 1 |
| 104 | ;; |
| 105 | esac |
| 106 | |
| 107 | # Check test results |
| 108 | test_result=$? |
| 109 | if [ $test_result -eq 0 ]; then |
| 110 | echo -e "${GREEN}All tests passed successfully!${NC}" |
| 111 | else |
| 112 | echo -e "${YELLOW}Some tests failed. Check the output above for more details.${NC}" |
| 113 | fi |
| 114 | |
| 115 | echo -e "${BLUE}====================================${NC}" |
| 116 | echo -e "${GREEN}Test run complete${NC}" |
| 117 | echo -e "${BLUE}====================================${NC}" |
| 118 | |
| 119 | # Deactivate Python virtual environment |
| 120 | deactivate |
| 121 | echo "Python virtual environment deactivated" |
| 122 | |
| 123 | echo "Press Enter to exit..." |
| 124 | read -r |