Branchwell

AI Resource Pro / website / run_tests.sh

1#!/bin/bash
2
3# Define paths
4SITE_DIR="/path/to/file"
5SELENIUM_DIR="$SITE_DIR/tests/selenium"
6
7# Function to check if a process is running on port 3001
8check_port() {
9 lsof -i:3001 > /dev/null
10 return $?
11}
12
13# Colors for output
14GREEN='\033[0;32m'
15YELLOW='\033[1;33m'
16BLUE='\033[0;34m'
17NC='\033[0m' # No Color
18
19echo -e "${BLUE}====================================${NC}"
20echo -e "${GREEN}AI Resource Pro Testing Script${NC}"
21echo -e "${BLUE}====================================${NC}"
22
23# Navigate to the project root
24echo -e "${YELLOW}Navigating to project root at $SITE_DIR${NC}"
25cd "$SITE_DIR" || { echo "Failed to navigate to $SITE_DIR"; exit 1; }
26
27# Check if Next.js app is already running
28if check_port; then
29 echo -e "${GREEN}Next.js app is already running on port 3001${NC}"
30else
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
47fi
48
49# Navigate to the Selenium tests directory
50echo -e "${YELLOW}Navigating to Selenium tests directory at $SELENIUM_DIR${NC}"
51cd "$SELENIUM_DIR" || { echo "Failed to navigate to $SELENIUM_DIR"; exit 1; }
52
53# Activate Python virtual environment
54echo -e "${YELLOW}Activating Python virtual environment...${NC}"
55if [ -d "venv" ]; then
56 source venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
57 echo -e "${GREEN}Virtual environment activated${NC}"
58else
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
70fi
71
72# Run the tests
73echo -e "${BLUE}====================================${NC}"
74echo -e "${GREEN}Running Selenium tests...${NC}"
75echo -e "${BLUE}====================================${NC}"
76echo "Available test options:"
77echo "1) Run single test (test_page_loads)"
78echo "2) Run all AI Coach tests"
79echo "3) Run all tests"
80echo "4) Run test_generate_roadmap test"
81echo "Enter your choice (1-4):"
82read -r test_choice
83
84case $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 ;;
105esac
106
107# Check test results
108test_result=$?
109if [ $test_result -eq 0 ]; then
110 echo -e "${GREEN}All tests passed successfully!${NC}"
111else
112 echo -e "${YELLOW}Some tests failed. Check the output above for more details.${NC}"
113fi
114
115echo -e "${BLUE}====================================${NC}"
116echo -e "${GREEN}Test run complete${NC}"
117echo -e "${BLUE}====================================${NC}"
118
119# Deactivate Python virtual environment
120deactivate
121echo "Python virtual environment deactivated"
122
123echo "Press Enter to exit..."
124read -r