7.4 KiB
7.4 KiB
AutoBackups - Playwright E2E Testing Integration
Overview
This project now includes comprehensive end-to-end (E2E) testing using Playwright, integrated with the Model Context Protocol (MCP) for automated testing of the AutoBackups Flask application.
Features
- 🎭 Cross-browser testing (Chromium, Firefox, WebKit)
- 🔧 Automated setup with the Flask development server
- 📊 Comprehensive reporting with HTML reports and screenshots
- 🐛 Debug mode for test development
- 🚀 CI/CD ready with GitHub Actions integration
- 📱 Responsive testing across different viewport sizes
- 🔌 API testing for backend endpoints
Test Suites
1. Dashboard Tests (dashboard.spec.js
)
- Main dashboard loading and rendering
- Navigation elements verification
- Responsive design testing across different viewports
- Visual regression testing with screenshots
2. Configuration Tests (configuration.spec.js
)
- Configuration page accessibility
- Form elements detection and interaction
- Data submission workflow
- Input validation testing
3. API Tests (api.spec.js
)
- Health check endpoints
- Backup API endpoints testing
- CORS headers validation
- POST request handling
4. Backup Workflow Tests (backup-workflow.spec.js
)
- Backup status display
- Manual backup trigger functionality
- Project list visualization
- Backup scheduling interface
- Progress and logging display
Quick Start
Prerequisites
-
Conda environment with AutoBackups dependencies:
conda env create -f environment.yml conda activate autobackups
-
Node.js dependencies:
npm install
-
Playwright browsers:
npx playwright install
Running Tests
Windows (PowerShell)
# Run all tests
.\run-tests.bat
# Run tests in headed mode (visible browser)
.\run-tests.bat headed
# Run specific test file
.\run-tests.bat specific tests/e2e/dashboard.spec.js
# Debug mode
.\run-tests.bat debug
# Show test report
.\run-tests.bat report
Linux/Mac (Bash)
# Make script executable
chmod +x run-tests.sh
# Run all tests
./run-tests.sh
# Run tests in headed mode
./run-tests.sh headed
# Run specific test file
./run-tests.sh specific tests/e2e/dashboard.spec.js
# Debug mode
./run-tests.sh debug
# Show test report
./run-tests.sh report
Direct NPX Commands
# Run all tests
npx playwright test
# Run tests with visible browser
npx playwright test --headed
# Run specific test file
npx playwright test tests/e2e/dashboard.spec.js
# Run in debug mode
npx playwright test --debug
# Generate and show HTML report
npx playwright show-report
Test Configuration
Playwright Config (playwright.config.js
)
Key configurations:
- Base URL:
http://localhost:5000
(Flask dev server) - Timeout: 30 seconds per test
- Retries: 2 retries on CI, 0 locally
- Browsers: Chromium, Firefox, WebKit
- Web Server: Automatically starts Flask app before tests
Test Data and Helpers
The tests/e2e/helpers/test-helpers.js
file provides:
- Common test utilities
- Form filling helpers
- Screenshot utilities
- Console logging setup
- Test data generators
Project Structure
├── tests/
│ └── e2e/
│ ├── dashboard.spec.js # Dashboard functionality tests
│ ├── configuration.spec.js # Configuration page tests
│ ├── api.spec.js # API endpoint tests
│ ├── backup-workflow.spec.js # Backup workflow tests
│ ├── setup.js # Global test setup
│ └── helpers/
│ └── test-helpers.js # Test utilities
├── playwright.config.js # Playwright configuration
├── package.json # Node.js dependencies
├── run-tests.sh # Linux/Mac test runner
├── run-tests.bat # Windows test runner
├── playwright-report/ # HTML test reports
└── test-results/ # Test artifacts and screenshots
Environment Variables
You can customize test behavior with environment variables:
# Custom base URL
export PLAYWRIGHT_BASE_URL=http://localhost:8080
# CI mode
export CI=true
# Debug mode
export DEBUG=pw:api
Continuous Integration
GitHub Actions
The project includes a GitHub Actions workflow (.github/workflows/e2e-tests.yml
) that:
- Sets up Python 3.12 with Conda
- Installs dependencies
- Runs Playwright tests
- Uploads test artifacts
- Generates test reports
Running in CI
Tests automatically run on:
- Push to
main
ordevelop
branches - Pull requests to
main
ordevelop
branches
Test Reports
HTML Report
- Interactive report with test results
- Screenshots and videos of failures
- Trace viewer for debugging
- Access via:
npx playwright show-report
JSON Report
- Machine-readable test results
- Located at:
test-results/playwright-results.json
- Useful for CI/CD integrations
Best Practices
Writing Tests
- Use Page Object Model for complex interactions
- Wait for elements properly with
page.waitForSelector()
- Take screenshots for visual verification
- Use data-testid attributes for reliable element selection
- Test across browsers by running full suite
Debugging Tests
- Headed mode: See browser interactions in real-time
- Debug mode: Step through tests with Playwright Inspector
- Console logs: Browser console messages are captured
- Screenshots: Automatic screenshots on failures
- Video recording: Videos of failed test runs
Performance
- Parallel execution: Tests run in parallel by default
- Selective testing: Run specific test files during development
- CI optimization: Different configurations for CI vs local development
Troubleshooting
Common Issues
- Port conflicts: Ensure Flask app port (5000) is available
- Conda environment: Make sure
autobackups
environment is activated - Browser installation: Run
npx playwright install
if browsers are missing - Timeouts: Increase timeout in
playwright.config.js
if needed
Debug Commands
# Check Playwright installation
npx playwright --version
# Verify browser installation
npx playwright install --dry-run
# Test configuration
npx playwright test --list
# Debug specific test
npx playwright test tests/e2e/dashboard.spec.js --debug
Integration with MCP
This Playwright setup is designed to work seamlessly with Model Context Protocol (MCP):
- Automated test generation based on application features
- Dynamic test adaptation as the application evolves
- Intelligent test selection based on code changes
- Report analysis and recommendation generation
Next Steps
- Expand test coverage for specific AutoBackups features
- Add visual regression testing with baseline screenshots
- Integrate performance testing with Playwright's performance APIs
- Set up test data management for more complex scenarios
- Add accessibility testing with axe-playwright integration