# World-Class Assessment Load Test - Usage Guide

## Overview

This load test script runs the **100% verified complete assessment flow** for multiple students:
1. Smart login (Excel password → Admin@123 fallback)
2. Password reset if needed
3. Profile completion if needed
4. Complete ONE domain assessment (all questions)
5. Submit assessment and handle feedback

## Key Features

✅ **CSV Range Support**: Run specific student ranges (perfect for multi-device execution)
✅ **Real-time Monitoring**: Live metrics every N students
✅ **100% Verified Flow**: Uses only tested, reliable components
✅ **Transparent Backend Analysis**: Comprehensive metrics for server performance
✅ **Multi-Device Ready**: Each device can run different ranges

## Usage

### Basic Command

```bash
cd /home/tech4biz/work/CP_Front_Automation_Test
source venv/bin/activate

python 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
```

### Multi-Device Execution

**Device 1** (Students 0-99):
```bash
python 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
```

**Device 2** (Students 100-199):
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 100 \
    --end 200 \
    --workers 100 \
    --headless \
    --metrics-interval 10
```

**Device 3** (Students 200-299):
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 200 \
    --end 300 \
    --workers 100 \
    --headless \
    --metrics-interval 10
```

**Device 4** (Students 300-399):
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 300 \
    --end 400 \
    --workers 100 \
    --headless \
    --metrics-interval 10
```

**Device 5** (Students 400-500):
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 400 \
    --end 500 \
    --workers 100 \
    --headless \
    --metrics-interval 10
```

## Arguments

| Argument | Description | Default | Example |
|----------|-------------|---------|---------|
| `--csv` | Path to CSV file (required) | - | `students_with_passwords_2025-12-12T13-19-32.csv` |
| `--start` | Start index (0-based, excluding header) | 0 | `0`, `100`, `200` |
| `--end` | End index (exclusive, None = all remaining) | None | `100`, `200`, `500` |
| `--workers` | Max concurrent workers | All students | `100`, `200`, `500` |
| `--headless` | Run in headless mode | True | (flag) |
| `--visible` | Run in visible mode (overrides headless) | False | (flag) |
| `--metrics-interval` | Print metrics every N students | 10 | `5`, `10`, `20` |

## CSV Format

The CSV must have these columns (case-insensitive):
- `Student CPID` or `student_cpid` or `cpid` or `CPID` (required)
- `Password` or `password` or `PASSWORD` (optional, will use Admin@123 if missing)
- `First Name` (optional, for display)
- `Last Name` (optional, for display)

## Real-Time Metrics

The script prints comprehensive metrics every N students (configurable):

```
📊 REAL-TIME METRICS
================================================================================
⏱️  Elapsed Time:        125.3s
✅ Completed:            50
❌ Failed:               2
📈 Success Rate:         96.2%
⚡ Rate:                 0.40 students/sec
⏳ Avg Duration:         245.6s
❓ Avg Questions:         12.3
📊 Total Questions:      615

📋 STEP METRICS:
   login                : 100.0% success, 2.1s avg
   password_reset       :  95.0% success, 3.5s avg
   profile_completion   :  90.0% success, 15.2s avg
   assessment           :  96.0% success, 220.5s avg
================================================================================
```

## Output Files

Results are saved to:
```
reports/load_tests/load_test_Complete_Assessment_Flow_{N}users_{timestamp}.json
```

## Best Practices

1. **Multi-Device Setup**: Divide students evenly across devices
   - 500 students = 5 devices × 100 students each
   - 1000 students = 10 devices × 100 students each

2. **Concurrency**: Start with `--workers` equal to number of students in range
   - For 100 students: `--workers 100`
   - Monitor system resources and adjust if needed

3. **Headless Mode**: Always use `--headless` for load testing
   - Much faster and more stable
   - Lower resource usage

4. **Metrics Interval**: Use `--metrics-interval 10` for frequent updates
   - Adjust based on test duration
   - Smaller intervals for shorter tests

5. **Range Validation**: 
   - `--start 0` means first student (after header)
   - `--end 100` means up to (but not including) index 100
   - So `--start 0 --end 100` runs students at indices 0-99

## Example: Running All 500 Students on 5 Devices

**Device 1**:
```bash
python 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
```

**Device 2**:
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 100 --end 200 --workers 100 --headless
```

**Device 3**:
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 200 --end 300 --workers 100 --headless
```

**Device 4**:
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 300 --end 400 --workers 100 --headless
```

**Device 5**:
```bash
python tests/load_tests/test_generic_load_assessments.py \
    --csv students_with_passwords_2025-12-12T13-19-32.csv \
    --start 400 --end 500 --workers 100 --headless
```

## Troubleshooting

**Issue**: "No students loaded"
- Check CSV path is correct
- Verify `--start` and `--end` are valid
- Ensure CSV has `Student CPID` column

**Issue**: High failure rate
- Reduce `--workers` (too many concurrent browsers)
- Check system resources (RAM, CPU)
- Verify backend is handling load

**Issue**: Slow execution
- Use `--headless` mode
- Reduce `--metrics-interval` (less frequent printing)
- Check network latency

## Notes

- **Password Strategy**: Excel password tried first, then Admin@123 fallback
- **Assessment Flow**: Completes ONE domain (first unlocked domain)
- **Question Types**: Handles all 5 question types automatically
- **Error Handling**: Robust retry logic for transient failures
- **Progress Tracking**: Real-time metrics show exactly what's happening

