E2E Test Coverage for FilmAffinity Backup Tool
Problem Statement
The current test suite lacks end-to-end (E2E) test coverage for the complete backup and upload workflows. While unit tests and integration tests exist for individual components, there's no automated testing of the full user journey from FilmAffinity data scraping to IMDb upload completion.
Current Test Coverage Analysis
Existing Test Types
Unit Tests (pytest with selenium mocking):
- ✅ Browser automation functions
- ✅ Data processing logic
- ✅ CSV validation
- ✅ Reporting utilities
- ✅ Command-line interface
Integration Tests (pytest -m integration):
- ✅ FilmAffinity HTTP scraping
- ✅ IMDbPY client initialization
- ✅ CSV format validation
- ✅ Data export pipelines
Missing Coverage:
- ❌ Full backup workflow (scrape → process → upload)
- ❌ Real browser interactions for IMDb login/upload
- ❌ End-to-end data integrity validation
- ❌ Error recovery scenarios
- ❌ Cross-platform compatibility
Proposed E2E Test Scenarios
Primary E2E Workflow
# Complete backup and upload cycle
filmaffinity-backup scrape --user 12345 --output data/
filmaffinity-backup upload --csv data/watched.csv --imdb-user test@example.com
Test Scenarios:
- Happy Path: Complete successful backup and upload
- Partial Upload: Resume interrupted upload
- Data Validation: Verify uploaded ratings match source data
- Error Recovery: Handle network failures, rate limiting, login issues
Secondary Scenarios
- Multi-user backup workflows
- Large dataset processing (>1000 movies)
- Different export formats (Letterboxd, JSON)
- Concurrent upload sessions
Technical Approach
Test Framework Selection
Recommendation: Playwright for browser automation + pytest-playwright
Rationale:
- Modern, reliable browser automation
- Cross-browser support (Chrome, Firefox, Safari, Edge)
- Built-in test generation and debugging tools
- Better stability than Selenium for E2E testing
- Active maintenance and community support
Alternative: Selenium with existing infrastructure (higher maintenance)
Test Environment Setup
Local Development:
# Install Playwright browsers
playwright install
# Run E2E tests
pytest tests/e2e/ --headed # Visual debugging
pytest tests/e2e/ --browser chromium --headed
CI/CD Integration:
# GitHub Actions example
- name: Install Playwright
run: |
pip install playwright pytest-playwright
playwright install-deps
playwright install chromium
- name: Run E2E Tests
run: pytest tests/e2e/ --browser chromium --video retain-on-failure
Test Data Strategy
Test Accounts:
- Dedicated FilmAffinity test user with known ratings
- IMDb test account for upload validation
- Pre-populated test datasets
Data Isolation:
- Use test-specific user IDs/accounts
- Clean up test data after execution
- Rate limiting awareness (FilmAffinity is strict)
Implementation Plan
Phase 1: Infrastructure Setup
-
Add Playwright dependencies
# pyproject.toml
[tool.pytest.ini_options]
addopts = "--browser chromium"
[project.optional-dependencies]
e2e = ["pytest-playwright", "playwright"]
-
Create E2E test directory structure
tests/e2e/
├── conftest.py # Playwright fixtures
├── test_full_backup.py # Main E2E scenarios
├── test_error_scenarios.py
├── test_data_integrity.py
└── fixtures/
├── test_users.json
└── sample_data/
-
Set up test fixtures
# tests/e2e/conftest.py
@pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
return {
**browser_context_args,
"record_video_dir": "test-results/videos/",
"record_har_path": "test-results/har/",
}
Phase 2: Core E2E Tests
Test 1: Complete Backup Workflow
def test_full_backup_workflow(page, test_user):
"""Test complete FilmAffinity → IMDb backup cycle."""
# Step 1: Scrape FilmAffinity data
run_cli_command(f"filmaffinity-backup scrape --user {test_user['fa_id']}")
# Step 2: Verify scraped data
csv_path = f"data/{test_user['fa_id']}/watched.csv"
assert_csv_has_expected_structure(csv_path)
# Step 3: Upload to IMDb (browser automation)
page.goto("https://www.imdb.com/")
login_to_imdb(page, test_user['imdb_credentials'])
# Step 4: Upload ratings
run_cli_command(f"filmaffinity-backup upload --csv {csv_path}")
# Step 5: Verify upload success
verify_ratings_on_imdb(page, expected_ratings)
Test 2: Error Recovery
def test_upload_resume_after_failure(page, test_user):
"""Test resuming upload after network interruption."""
# Simulate partial upload
# Trigger network failure mid-upload
# Verify resume functionality
# Confirm all ratings eventually uploaded
Test 3: Data Integrity
def test_data_integrity_preservation(page, test_user):
"""Verify uploaded ratings match source data exactly."""
# Compare FilmAffinity ratings with IMDb ratings
# Validate all metadata (titles, years, scores)
# Check for data corruption or loss
Phase 3: CI/CD Integration
- GitHub Actions workflow
- Parallel test execution
- Artifact collection (videos, HAR files, screenshots)
- Test result reporting
Phase 4: Maintenance & Monitoring
- Test stability monitoring
- IMDb/FilmAffinity website change detection
- Automated test data refresh
- Performance regression tracking
Acceptance Criteria
Functional Requirements
Quality Requirements
Documentation Requirements
Dependencies & Prerequisites
External Dependencies
- IMDb test account with known ratings
- FilmAffinity test user profile
- Stable internet connection for CI
- Sufficient rate limit allowances
Internal Dependencies
Risk Assessment
High Risk
- Rate Limiting: FilmAffinity/IMDb may block test accounts
- Website Changes: IMDb/FilmAffinity UI updates break tests
- Test Data Management: Maintaining test accounts and data
Mitigation Strategies
- Rate Limiting: Use dedicated test accounts, implement delays
- Website Changes: Regular test maintenance, change detection alerts
- Test Data: Automated test data refresh, multiple test accounts
Success Metrics
- Coverage: E2E tests cover 80%+ of user workflows
- Reliability: <5% flaky test rate
- Speed: E2E test suite completes in <15 minutes
- Maintenance: <2 hours/month for test upkeep
References
E2E Test Coverage for FilmAffinity Backup Tool
Problem Statement
The current test suite lacks end-to-end (E2E) test coverage for the complete backup and upload workflows. While unit tests and integration tests exist for individual components, there's no automated testing of the full user journey from FilmAffinity data scraping to IMDb upload completion.
Current Test Coverage Analysis
Existing Test Types
Unit Tests (
pytestwith selenium mocking):Integration Tests (
pytest -m integration):Missing Coverage:
Proposed E2E Test Scenarios
Primary E2E Workflow
# Complete backup and upload cycle filmaffinity-backup scrape --user 12345 --output data/ filmaffinity-backup upload --csv data/watched.csv --imdb-user test@example.comTest Scenarios:
Secondary Scenarios
Technical Approach
Test Framework Selection
Recommendation: Playwright for browser automation + pytest-playwright
Rationale:
Alternative: Selenium with existing infrastructure (higher maintenance)
Test Environment Setup
Local Development:
CI/CD Integration:
Test Data Strategy
Test Accounts:
Data Isolation:
Implementation Plan
Phase 1: Infrastructure Setup
Add Playwright dependencies
Create E2E test directory structure
Set up test fixtures
Phase 2: Core E2E Tests
Test 1: Complete Backup Workflow
Test 2: Error Recovery
Test 3: Data Integrity
Phase 3: CI/CD Integration
Phase 4: Maintenance & Monitoring
Acceptance Criteria
Functional Requirements
Quality Requirements
Documentation Requirements
Dependencies & Prerequisites
External Dependencies
Internal Dependencies
Risk Assessment
High Risk
Mitigation Strategies
Success Metrics
References