diff --git a/SETUP_GUIDE.md b/SETUP_GUIDE.md new file mode 100644 index 0000000..abe1ea4 --- /dev/null +++ b/SETUP_GUIDE.md @@ -0,0 +1,230 @@ +# Complete Setup Guide - Load Testing Environment + +## đŸ“Ļ What's Included + +### 1. `requirements.txt` +Complete list of Python dependencies needed for load testing: +- pytest (testing framework) +- selenium (browser automation) +- webdriver-manager (automatic ChromeDriver management) +- And more... + +### 2. `setup_load_test_environment.sh` +World-class setup script that: +- ✅ Checks Python version (3.8+) +- ✅ Creates virtual environment +- ✅ Installs all dependencies +- ✅ Validates Chrome/ChromeDriver +- ✅ Verifies function signature +- ✅ Creates necessary directories +- ✅ Provides clear feedback and next steps + +## 🚀 Quick Start + +### For Fresh Systems + +```bash +# 1. Navigate to project +cd /home/tech4biz/work/CP_Front_Automation_Test + +# 2. Run setup script +./setup_load_test_environment.sh + +# 3. Activate virtual environment (if not auto-activated) +source venv/bin/activate + +# 4. Validate setup +python3 tests/load_tests/validate_function_signature.py + +# 5. Run your first test +python3 tests/load_tests/test_generic_load_assessments.py \ + --csv your_students.csv \ + --start 0 --end 1 \ + --workers 1 --headless +``` + +## 📋 What the Setup Script Does + +### Step-by-Step Process + +1. **Python Check** - Verifies Python 3.8+ is installed +2. **pip Check** - Ensures pip is available +3. **Virtual Environment** - Creates/validates venv +4. **Dependencies** - Installs all packages from requirements.txt +5. **Chrome Check** - Verifies Chrome browser (or notes auto-install) +6. **ChromeDriver** - Notes that webdriver-manager handles it automatically +7. **Function Validation** - Validates load test function signature +8. **Project Structure** - Verifies all required files/directories exist +9. **Reports Directory** - Creates reports/load_tests directory +10. **Final Verification** - Tests Python imports + +### Output Example + +``` +================================================================================ +🚀 World-Class Load Test Environment Setup +================================================================================ + +Step 1: Checking Python version... +✅ Python 3.10.12 found (>= 3.8 required) + +Step 2: Checking pip... +✅ pip3 found + +Step 3: Setting up virtual environment... +✅ Virtual environment created + +Step 4: Activating virtual environment... +✅ Virtual environment activated + +Step 5: Upgrading pip... +✅ pip upgraded to latest version + +Step 6: Installing Python dependencies... +✅ All Python dependencies installed + +Step 7: Checking Chrome browser... +✅ Chrome found: Google Chrome 120.0.6099.109 + +Step 8: Checking ChromeDriver... +âš ī¸ ChromeDriver not found in PATH +â„šī¸ webdriver-manager will automatically download and manage ChromeDriver +✅ ChromeDriver will be handled automatically + +Step 9: Validating load test function signature... +✅ Function signature validation passed + +Step 10: Validating project structure... +✅ Directory exists: pages +✅ Directory exists: utils +✅ Directory exists: tests/load_tests +✅ Directory exists: config +✅ File exists: tests/load_tests/test_generic_load_assessments.py +✅ File exists: config/config.py + +Step 11: Creating reports directory... +✅ Reports directory created: reports/load_tests + +Step 12: Final verification... +✅ Core dependencies imported successfully +✅ Python imports working correctly + +================================================================================ +✅ Setup Complete! +================================================================================ + +📋 Next Steps: +... +``` + +## 🔧 Manual Setup (Alternative) + +If you prefer manual setup or the script doesn't work: + +```bash +# 1. Create virtual environment +python3 -m venv venv + +# 2. Activate it +source venv/bin/activate + +# 3. Upgrade pip +pip install --upgrade pip + +# 4. Install dependencies +pip install -r requirements.txt + +# 5. Validate +python3 tests/load_tests/validate_function_signature.py +``` + +## ✅ Verification Checklist + +After setup, verify everything works: + +- [ ] Virtual environment created and activated +- [ ] All dependencies installed (`pip list` shows selenium, pytest, etc.) +- [ ] Function signature validated (no errors) +- [ ] Chrome browser accessible +- [ ] Project structure intact +- [ ] Reports directory created + +## 🐛 Troubleshooting + +### Issue: "Permission denied" when running setup script + +**Solution:** +```bash +chmod +x setup_load_test_environment.sh +./setup_load_test_environment.sh +``` + +### Issue: "Python 3 not found" + +**Solution:** +```bash +# Ubuntu/Debian +sudo apt-get update +sudo apt-get install python3 python3-pip python3-venv + +# Or check if python3 is installed +which python3 +``` + +### Issue: "pip install fails" + +**Solution:** +```bash +# Upgrade pip first +python3 -m pip install --upgrade pip + +# Then install requirements +pip install -r requirements.txt +``` + +### Issue: "Chrome not found" + +**Solution:** +```bash +# Ubuntu/Debian +wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +sudo dpkg -i google-chrome-stable_current_amd64.deb +sudo apt-get install -f # Fix dependencies if needed +``` + +**Note:** webdriver-manager will handle ChromeDriver automatically, so you don't need to install it manually. + +## 📚 Related Files + +- `requirements.txt` - Python dependencies +- `setup_load_test_environment.sh` - Automated setup script +- `tests/load_tests/README.md` - Complete documentation +- `tests/load_tests/QUICK_START.md` - Quick reference +- `tests/load_tests/validate_function_signature.py` - Validation script + +## đŸŽ¯ Next Steps + +After setup is complete: + +1. **Validate Setup:** + ```bash + python3 tests/load_tests/validate_function_signature.py + ``` + +2. **Run First Test:** + ```bash + python3 tests/load_tests/test_generic_load_assessments.py \ + --csv your_students.csv \ + --start 0 --end 1 \ + --workers 1 --headless + ``` + +3. **Read Documentation:** + - Full guide: `tests/load_tests/README.md` + - Quick start: `tests/load_tests/QUICK_START.md` + +--- + +**Status:** ✅ Production Ready +**Last Updated:** 2025-12-12 + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3e33b13 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,21 @@ +# Cognitive Prism Automation Testing - Requirements +# Python 3.8+ required + +# Core Testing Framework +pytest>=7.4.0 +pytest-html>=3.2.0 +pytest-xdist>=3.3.0 # For parallel test execution + +# Selenium WebDriver +selenium>=4.15.0 +webdriver-manager>=4.0.0 # Automatic ChromeDriver management + +# Data Handling +pandas>=2.0.0 # For CSV/data manipulation (if needed) + +# Utilities +python-dotenv>=1.0.0 # For environment variables + +# Optional but recommended +requests>=2.31.0 # For API testing (if needed) + diff --git a/setup_load_test_environment.sh b/setup_load_test_environment.sh new file mode 100755 index 0000000..7314b62 --- /dev/null +++ b/setup_load_test_environment.sh @@ -0,0 +1,243 @@ +#!/bin/bash + +################################################################################ +# World-Class Load Test Environment Setup Script +# +# This script sets up everything needed for load testing on a fresh system. +# It checks all prerequisites, installs dependencies, and validates the setup. +# +# Usage: ./setup_load_test_environment.sh +################################################################################ + +set -e # Exit on any error + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Script directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PROJECT_ROOT="$SCRIPT_DIR" + +echo -e "${BLUE}================================================================================${NC}" +echo -e "${BLUE}🚀 World-Class Load Test Environment Setup${NC}" +echo -e "${BLUE}================================================================================${NC}" +echo "" + +# Function to print status +print_status() { + echo -e "${GREEN}✅ $1${NC}" +} + +print_warning() { + echo -e "${YELLOW}âš ī¸ $1${NC}" +} + +print_error() { + echo -e "${RED}❌ $1${NC}" +} + +print_info() { + echo -e "${BLUE}â„šī¸ $1${NC}" +} + +# Step 1: Check Python version +echo -e "${BLUE}Step 1: Checking Python version...${NC}" +if command -v python3 &> /dev/null; then + PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}') + PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1) + PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2) + + if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 8 ]; then + print_status "Python $PYTHON_VERSION found (>= 3.8 required)" + else + print_error "Python $PYTHON_VERSION found, but 3.8+ is required" + exit 1 + fi +else + print_error "Python 3 not found. Please install Python 3.8 or higher." + exit 1 +fi + +# Step 2: Check pip +echo "" +echo -e "${BLUE}Step 2: Checking pip...${NC}" +if command -v pip3 &> /dev/null; then + print_status "pip3 found" +else + print_error "pip3 not found. Please install pip." + exit 1 +fi + +# Step 3: Check/create virtual environment +echo "" +echo -e "${BLUE}Step 3: Setting up virtual environment...${NC}" +if [ -d "$PROJECT_ROOT/venv" ]; then + print_warning "Virtual environment already exists" + read -p "Do you want to recreate it? (y/N): " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + print_info "Removing existing virtual environment..." + rm -rf "$PROJECT_ROOT/venv" + python3 -m venv "$PROJECT_ROOT/venv" + print_status "Virtual environment created" + else + print_status "Using existing virtual environment" + fi +else + python3 -m venv "$PROJECT_ROOT/venv" + print_status "Virtual environment created" +fi + +# Step 4: Activate virtual environment +echo "" +echo -e "${BLUE}Step 4: Activating virtual environment...${NC}" +source "$PROJECT_ROOT/venv/bin/activate" +print_status "Virtual environment activated" + +# Step 5: Upgrade pip +echo "" +echo -e "${BLUE}Step 5: Upgrading pip...${NC}" +pip install --upgrade pip --quiet +print_status "pip upgraded to latest version" + +# Step 6: Install requirements +echo "" +echo -e "${BLUE}Step 6: Installing Python dependencies...${NC}" +if [ -f "$PROJECT_ROOT/requirements.txt" ]; then + pip install -r "$PROJECT_ROOT/requirements.txt" --quiet + print_status "All Python dependencies installed" +else + print_error "requirements.txt not found at $PROJECT_ROOT/requirements.txt" + exit 1 +fi + +# Step 7: Check Chrome browser +echo "" +echo -e "${BLUE}Step 7: Checking Chrome browser...${NC}" +if command -v google-chrome &> /dev/null || command -v chromium-browser &> /dev/null || command -v chrome &> /dev/null; then + CHROME_CMD=$(command -v google-chrome || command -v chromium-browser || command -v chrome) + CHROME_VERSION=$($CHROME_CMD --version 2>&1 | head -n1) + print_status "Chrome found: $CHROME_VERSION" +else + print_warning "Chrome browser not found in PATH" + print_info "Chrome will be installed automatically by webdriver-manager if needed" + print_info "Or install manually: sudo apt-get install google-chrome-stable (Ubuntu/Debian)" +fi + +# Step 8: Check ChromeDriver +echo "" +echo -e "${BLUE}Step 8: Checking ChromeDriver...${NC}" +if command -v chromedriver &> /dev/null; then + CHROMEDRIVER_VERSION=$(chromedriver --version 2>&1 | head -n1) + print_status "ChromeDriver found: $CHROMEDRIVER_VERSION" + print_info "Note: webdriver-manager will handle ChromeDriver automatically if needed" +else + print_warning "ChromeDriver not found in PATH" + print_info "webdriver-manager will automatically download and manage ChromeDriver" + print_status "ChromeDriver will be handled automatically" +fi + +# Step 9: Validate function signature +echo "" +echo -e "${BLUE}Step 9: Validating load test function signature...${NC}" +if [ -f "$PROJECT_ROOT/tests/load_tests/validate_function_signature.py" ]; then + if python3 "$PROJECT_ROOT/tests/load_tests/validate_function_signature.py" 2>/dev/null; then + print_status "Function signature validation passed" + else + print_warning "Function signature validation had issues (this is okay if dependencies aren't fully set up yet)" + fi +else + print_warning "Validation script not found (this is okay)" +fi + +# Step 10: Check project structure +echo "" +echo -e "${BLUE}Step 10: Validating project structure...${NC}" +REQUIRED_DIRS=("pages" "utils" "tests/load_tests" "config") +REQUIRED_FILES=("tests/load_tests/test_generic_load_assessments.py" "config/config.py") + +ALL_GOOD=true +for dir in "${REQUIRED_DIRS[@]}"; do + if [ -d "$PROJECT_ROOT/$dir" ]; then + print_status "Directory exists: $dir" + else + print_error "Required directory missing: $dir" + ALL_GOOD=false + fi +done + +for file in "${REQUIRED_FILES[@]}"; do + if [ -f "$PROJECT_ROOT/$file" ]; then + print_status "File exists: $file" + else + print_error "Required file missing: $file" + ALL_GOOD=false + fi +done + +if [ "$ALL_GOOD" = false ]; then + print_error "Project structure validation failed" + exit 1 +fi + +# Step 11: Create reports directory +echo "" +echo -e "${BLUE}Step 11: Creating reports directory...${NC}" +mkdir -p "$PROJECT_ROOT/reports/load_tests" +print_status "Reports directory created: reports/load_tests" + +# Step 12: Final verification +echo "" +echo -e "${BLUE}Step 12: Final verification...${NC}" + +# Test Python imports +python3 -c " +import sys +try: + import selenium + import pytest + print('✅ Core dependencies imported successfully') +except ImportError as e: + print(f'❌ Import error: {e}') + sys.exit(1) +" 2>/dev/null + +if [ $? -eq 0 ]; then + print_status "Python imports working correctly" +else + print_error "Python imports failed" + exit 1 +fi + +# Summary +echo "" +echo -e "${GREEN}================================================================================${NC}" +echo -e "${GREEN}✅ Setup Complete!${NC}" +echo -e "${GREEN}================================================================================${NC}" +echo "" +echo -e "${BLUE}📋 Next Steps:${NC}" +echo "" +echo "1. Activate virtual environment:" +echo -e " ${YELLOW}source venv/bin/activate${NC}" +echo "" +echo "2. Validate function signature:" +echo -e " ${YELLOW}python3 tests/load_tests/validate_function_signature.py${NC}" +echo "" +echo "3. Run your first load test (1 student):" +echo -e " ${YELLOW}python3 tests/load_tests/test_generic_load_assessments.py \\${NC}" +echo -e " ${YELLOW} --csv your_students.csv \\${NC}" +echo -e " ${YELLOW} --start 0 --end 1 \\${NC}" +echo -e " ${YELLOW} --workers 1 --headless${NC}" +echo "" +echo -e "${BLUE}📚 Documentation:${NC}" +echo " - Full guide: tests/load_tests/README.md" +echo " - Quick reference: tests/load_tests/LOAD_TEST_USAGE.md" +echo " - Issue resolution: tests/load_tests/VERIFICATION_SUMMARY.md" +echo "" +echo -e "${GREEN}🎉 You're ready to run load tests!${NC}" +echo "" + diff --git a/tests/load_tests/QUICK_START.md b/tests/load_tests/QUICK_START.md new file mode 100644 index 0000000..b1f6db8 --- /dev/null +++ b/tests/load_tests/QUICK_START.md @@ -0,0 +1,83 @@ +# Quick Start Guide - Load Testing + +## 🚀 For Fresh Systems + +### One-Command Setup + +```bash +cd /home/tech4biz/work/CP_Front_Automation_Test +./setup_load_test_environment.sh +``` + +This will set up everything automatically! + +## 📝 Manual Setup (If Needed) + +### 1. Check Python +```bash +python3 --version # Should be 3.8+ +``` + +### 2. Create Virtual Environment +```bash +python3 -m venv venv +``` + +### 3. Activate Virtual Environment +```bash +source venv/bin/activate +``` + +### 4. Install Dependencies +```bash +pip install -r requirements.txt +``` + +### 5. Validate Setup +```bash +python3 tests/load_tests/validate_function_signature.py +``` + +## ✅ Run Your First Test + +### Test with 1 Student +```bash +source venv/bin/activate + +python3 tests/load_tests/test_generic_load_assessments.py \ + --csv students_with_passwords_2025-12-12T13-19-32.csv \ + --start 0 \ + --end 1 \ + --workers 1 \ + --headless \ + --metrics-interval 1 +``` + +### Scale Up to 10 Students +```bash +python3 tests/load_tests/test_generic_load_assessments.py \ + --csv students_with_passwords_2025-12-12T13-19-32.csv \ + --start 0 \ + --end 10 \ + --workers 10 \ + --headless \ + --metrics-interval 5 +``` + +### Full Load Test (100 Students) +```bash +python3 tests/load_tests/test_generic_load_assessments.py \ + --csv students_with_passwords_2025-12-12T13-19-32.csv \ + --start 0 \ + --end 100 \ + --workers 100 \ + --headless \ + --metrics-interval 10 +``` + +## 📚 Need More Help? + +- **Full Documentation**: `tests/load_tests/README.md` +- **Usage Guide**: `tests/load_tests/LOAD_TEST_USAGE.md` +- **Issue Resolution**: `tests/load_tests/VERIFICATION_SUMMARY.md` + diff --git a/tests/load_tests/README.md b/tests/load_tests/README.md index e9a5d0b..d3f8bc1 100644 --- a/tests/load_tests/README.md +++ b/tests/load_tests/README.md @@ -46,11 +46,42 @@ This is a **world-class load testing script** that simulates multiple students c ### Required - ✅ Python 3.8+ - ✅ Virtual environment activated -- ✅ Chrome browser installed -- ✅ ChromeDriver installed +- ✅ Chrome browser installed (or will be auto-managed) +- ✅ ChromeDriver (auto-managed by webdriver-manager) - ✅ CSV file with student data - ✅ Backend server running (localhost:3983 for local) +### 🚀 Quick Setup (Fresh System) + +**For a completely fresh system, run the setup script:** + +```bash +cd /home/tech4biz/work/CP_Front_Automation_Test +chmod +x setup_load_test_environment.sh +./setup_load_test_environment.sh +``` + +This script will: +- ✅ Check Python version (3.8+) +- ✅ Create virtual environment +- ✅ Install all dependencies from `requirements.txt` +- ✅ Check Chrome/ChromeDriver +- ✅ Validate project structure +- ✅ Verify function signature +- ✅ Create necessary directories + +**Manual Setup (if needed):** +```bash +# 1. Create virtual environment +python3 -m venv venv + +# 2. Activate it +source venv/bin/activate + +# 3. Install dependencies +pip install -r requirements.txt +``` + ### CSV File Format Your CSV file must have these columns (case-insensitive): @@ -70,7 +101,15 @@ STU002,Pass456,Jane,Smith ## 🚀 Quick Start -### Step 1: Activate Virtual Environment +### Step 0: Setup (First Time Only) + +**If this is a fresh system, run the setup script first:** +```bash +cd /home/tech4biz/work/CP_Front_Automation_Test +./setup_load_test_environment.sh +``` + +**If already set up, just activate the virtual environment:** ```bash cd /home/tech4biz/work/CP_Front_Automation_Test source venv/bin/activate