CP_AUTOMATION/tests/README.md
2025-12-12 19:54:54 +05:30

172 lines
5.2 KiB
Markdown

# Test Suite Organization
This directory contains all automated tests organized by functionality following world-class best practices.
## Directory Structure
```
tests/
├── conftest.py # Shared pytest fixtures and configuration
├── student_authentication/ # Authentication-related tests
│ ├── __init__.py
│ ├── test_login.py # Login functionality tests
│ ├── test_logout.py # Logout functionality tests
│ ├── test_password_reset.py # Password reset tests
│ └── test_complete_student_flow.py # Complete authentication flow
├── student_profile/ # Profile-related tests
│ ├── __init__.py
│ └── test_profile_filling.py # Profile completion tests
└── student_assessment/ # Assessment-related tests (Future)
└── __init__.py
```
## Test Categories
### 1. Student Authentication (`student_authentication/`)
Tests for student authentication flows:
- **`test_login.py`**: Login functionality
- ✅ Successful login
- ✅ Login with invalid credentials
- ✅ Login with remember me
- ✅ Login form elements visibility
- **`test_logout.py`**: Logout functionality
- ✅ Logout from dashboard
- ✅ Logout after password reset
- ⚠️ Note: Logout functionality may need UI implementation
- **`test_password_reset.py`**: Password reset functionality
- ✅ Password reset for new student (first login)
- ✅ Password reset check for already reset student
- ✅ Password reset form validation
- ✅ Change password to standard (Admin@123)
- **`test_complete_student_flow.py`**: Complete authentication flow
- ✅ Login → Password Reset → Dashboard → Logout sequence
- ✅ Password reset sequence validation
### 2. Student Profile (`student_profile/`)
Tests for student profile management:
- **`test_profile_filling.py`**: Profile completion
- ✅ Profile incomplete modal appears
- ✅ Navigation to profile editor
- ✅ Profile editor page loads
- ✅ All profile tabs accessible
- ✅ Complete profile filling with data
### 3. Student Assessment (`student_assessment/`)
Tests for assessment flows (Future implementation):
- Assessment navigation
- Domain completion
- Question answering
- Feedback submission
## Running Tests
### Run all tests:
```bash
pytest tests/ -v
```
### Run specific category:
```bash
# Authentication tests
pytest tests/student_authentication/ -v
# Profile tests
pytest tests/student_profile/ -v
# Assessment tests (when implemented)
pytest tests/student_assessment/ -v
```
### Run specific test file:
```bash
pytest tests/student_authentication/test_login.py -v
pytest tests/student_profile/test_profile_filling.py -v
```
### Run specific test:
```bash
pytest tests/student_authentication/test_login.py::TestLogin::test_login_success -v
```
### Run with markers:
```bash
pytest -m authentication -v
pytest -m profile -v
pytest -m assessment -v
```
## Test Execution Order
Tests are designed to be independent, but follow this logical sequence:
1. **Authentication** (Login, Password Reset, Logout)
2. **Profile** (Profile Completion)
3. **Assessment** (Assessment Navigation, Completion)
## Best Practices Followed
### ✅ Framework Structure
- **Organized by functionality** - Clear separation of concerns
- **Proper package structure** - `__init__.py` files for Python packages
- **Shared fixtures** - `conftest.py` for common setup/teardown
- **Test isolation** - Each test is independent
### ✅ Naming Conventions
- **Files**: `test_*.py` (pytest requirement)
- **Classes**: `Test*` (pytest requirement)
- **Methods**: `test_*` (pytest requirement)
- **Descriptive names**: Clear indication of what is being tested
### ✅ Test Organization
- **One test class per feature** - Easy to locate and maintain
- **Grouped by functionality** - Related tests together
- **Clear test structure** - Setup → Action → Assertion
### ✅ Code Quality
- **Page Object Model** - All page interactions through page objects
- **Explicit waits** - No hard-coded sleeps
- **Error handling** - Proper exception handling
- **Documentation** - Docstrings for all test methods
## Test Data
Tests use fixtures for test data:
- `new_student_credentials`: New student (not yet reset password)
- `existing_student_credentials`: Existing student (already reset password)
- `new_student_with_data`: New student with complete profile data
**TODO**: Update fixtures to read from Excel file with actual student data.
## Prerequisites
Before running tests:
1. ✅ Login functionality must work
2. ✅ Password reset functionality must work
3. ✅ Profile editor must be accessible
4. ✅ All `data-testid` attributes must be present in UI
## Next Steps
1. ✅ Complete authentication tests
2. ✅ Complete profile tests
3. ⏳ Implement assessment tests
4. ⏳ Add integration tests
5. ⏳ Add performance tests
## Notes
- All tests follow the **Page Object Model** pattern
- All tests use **explicit waits** (no `time.sleep()`)
- All tests use **data-testid** locators (best practice)
- Password tracking system prevents ambiguity after password reset
- Test sequence ensures password reset happens before other operations