188 lines
4.1 KiB
Markdown
188 lines
4.1 KiB
Markdown
# E2E Tests
|
|
|
|
End-to-end tests for the Cyber Hybrid Hub application using Playwright.
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
# Install dependencies
|
|
cd .playwright-mcp && npm install
|
|
|
|
# Install browsers
|
|
npx playwright install --with-deps chromium
|
|
|
|
# Run all tests
|
|
npx playwright test
|
|
|
|
# Run tests in UI mode
|
|
npx playwright test --ui
|
|
|
|
# View HTML report
|
|
npx playwright show-report
|
|
```
|
|
|
|
## Test Organization
|
|
|
|
```
|
|
tests/e2e/
|
|
├── helpers/ # Test utilities and fixtures
|
|
│ └── test-utils.ts
|
|
├── auth/ # Authentication and authorization
|
|
│ ├── login.spec.ts
|
|
│ ├── logout.spec.ts
|
|
│ └── rbac.spec.ts
|
|
├── landlord/ # Landlord-specific features
|
|
│ ├── applications.spec.ts
|
|
│ ├── dashboard.spec.ts
|
|
│ ├── leases.spec.ts
|
|
│ ├── maintenance.spec.ts
|
|
│ ├── payments.spec.ts
|
|
│ └── properties.spec.ts
|
|
├── tenant/ # Tenant-specific features
|
|
│ ├── applications.spec.ts
|
|
│ ├── leases.spec.ts
|
|
│ ├── maintenance.spec.ts
|
|
│ └── payments.spec.ts
|
|
└── error-handling/ # Error scenarios and edge cases
|
|
└── validation.spec.ts
|
|
```
|
|
|
|
## Running Specific Tests
|
|
|
|
```bash
|
|
# Run all auth tests
|
|
npx playwright test tests/e2e/auth/
|
|
|
|
# Run specific test file
|
|
npx playwright test tests/e2e/auth/login.spec.ts
|
|
|
|
# Run tests matching pattern
|
|
npx playwright test --grep "login"
|
|
```
|
|
|
|
## Test Modes
|
|
|
|
```bash
|
|
# Headed mode (show browser)
|
|
npx playwright test --headed
|
|
|
|
# Debug mode with inspector
|
|
npx playwright test --debug
|
|
|
|
# UI mode (interactive test explorer)
|
|
npx playwright test --ui
|
|
|
|
# Slow motion
|
|
npx playwright test --headed --slow-mo=1000
|
|
```
|
|
|
|
## E2E Test Mode
|
|
|
|
The application supports E2E test mode to bypass OAuth authentication:
|
|
|
|
```typescript
|
|
// Set E2E mode
|
|
await page.addInitScript(() => {
|
|
globalThis.localStorage.setItem("E2E_TEST", "true");
|
|
});
|
|
|
|
// Use E2E user headers
|
|
await page.goto("/protected-route", {
|
|
headers: {
|
|
"x-e2e-user": "landlord", // or "tenant", "admin"
|
|
},
|
|
});
|
|
```
|
|
|
|
### E2E Test Users
|
|
|
|
- **`landlord`**: Alex Landlord (properties: e2e-prop-1, e2e-prop-2)
|
|
- **`tenant`**: Sam Tenant (lease: e2e-lease-1)
|
|
- **`admin`**: System administrator
|
|
|
|
## Configuration
|
|
|
|
Playwright is configured in `playwright.config.ts`:
|
|
|
|
- **Timeout**: 60 seconds per test
|
|
- **Workers**: 1 (local), 2 (CI)
|
|
- **Retries**: 0 (local), 2 (CI)
|
|
- **Reporters**: HTML, JSON, JUnit, List
|
|
- **Browsers**: Chromium
|
|
|
|
## CI/CD
|
|
|
|
Tests run automatically on:
|
|
|
|
- Push to main/develop branches
|
|
- Pull requests
|
|
- Daily schedule (2 AM UTC)
|
|
- Manual trigger
|
|
|
|
See `.github/workflows/e2e-tests.yml` for configuration.
|
|
|
|
## Documentation
|
|
|
|
For comprehensive testing documentation, see
|
|
[E2E_TEST_GUIDE.md](./E2E_TEST_GUIDE.md).
|
|
|
|
Topics covered:
|
|
|
|
- Writing tests
|
|
- Debugging techniques
|
|
- Best practices
|
|
- Troubleshooting
|
|
- CI/CD integration
|
|
- Performance optimization
|
|
|
|
## Test Coverage
|
|
|
|
Current test coverage includes:
|
|
|
|
- ✅ Authentication flows (login, logout, RBAC)
|
|
- ✅ Landlord features (dashboard, properties, applications, leases,
|
|
maintenance, payments)
|
|
- ✅ Tenant features (applications, leases, maintenance, payments)
|
|
- ✅ Error handling (validation, network errors, unauthorized access, session
|
|
expiration)
|
|
- ✅ Edge cases (empty data, special characters, concurrent users, data
|
|
isolation)
|
|
|
|
## Stats
|
|
|
|
- **Total Tests**: 200+
|
|
- **Test Files**: 13
|
|
- **Categories**: 4 (Auth, Landlord, Tenant, Error Handling)
|
|
- **Browser**: Chromium
|
|
|
|
## Contributing
|
|
|
|
When adding new tests:
|
|
|
|
1. Follow existing test structure and patterns
|
|
2. Use descriptive test names
|
|
3. Track console errors
|
|
4. Use conditional assertions for missing features
|
|
5. Group related tests with `test.describe`
|
|
6. Update this README if adding new categories
|
|
|
|
## Debugging Failed Tests
|
|
|
|
```bash
|
|
# Run failed tests only
|
|
npx playwright test --repeat-each=0
|
|
|
|
# Run with trace
|
|
npx playwright test --trace on
|
|
|
|
# View trace file
|
|
npx playwright show-trace test-results/trace.zip
|
|
```
|
|
|
|
Test artifacts are saved to:
|
|
|
|
- Screenshots: `test-results/`
|
|
- Videos: `test-results/`
|
|
- Traces: `playwright-trace/`
|
|
- HTML Report: `playwright-report/`
|