|
| 1 | +# E2E Testing with Playwright |
| 2 | + |
| 3 | +This package contains end-to-end tests for the frontend application using Playwright. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +The E2E tests are configured to run against your Next.js frontend application running on `http://localhost:3000`. |
| 8 | + |
| 9 | +## Running Tests |
| 10 | + |
| 11 | +### Locally |
| 12 | + |
| 13 | +1. **Start the frontend application:** |
| 14 | + ```bash |
| 15 | + # From project root |
| 16 | + pnpm --filter @infinum/frontend dev |
| 17 | + ``` |
| 18 | + |
| 19 | +2. **Run E2E tests:** |
| 20 | + ```bash |
| 21 | + # From project root |
| 22 | + pnpm e2e |
| 23 | + |
| 24 | + # Or with different modes |
| 25 | + pnpm --filter e2e-frontend test:headed # See browser window |
| 26 | + pnpm --filter e2e-frontend test:debug # Step-by-step debugging |
| 27 | + pnpm --filter e2e-frontend test:ui # Interactive UI mode |
| 28 | + ``` |
| 29 | + |
| 30 | +### In CI/CD |
| 31 | + |
| 32 | +The tests automatically run in GitHub Actions on: |
| 33 | +- Push to `main`/`master` branches |
| 34 | +- Pull requests to `main`/`master` branches |
| 35 | +- Manual workflow dispatch |
| 36 | + |
| 37 | +## Test Structure |
| 38 | + |
| 39 | +- **`home.spec.ts`** - Homepage functionality and visual regression |
| 40 | +- **`login.spec.ts`** - Authentication flows |
| 41 | +- **`home-axe.spec.ts`** - Accessibility testing |
| 42 | +- **`multi-device.spec.ts`** - Responsive design testing |
| 43 | +- **`pages/`** - Page Object Models for reusable page interactions |
| 44 | +- **`utils/`** - Shared test utilities |
| 45 | + |
| 46 | +## Configuration |
| 47 | + |
| 48 | +- **Base config:** `../test-utils/base.playwright.config.ts` |
| 49 | +- **Local config:** `playwright.config.ts` |
| 50 | + |
| 51 | +## Key Features |
| 52 | + |
| 53 | +### Visual Regression Testing |
| 54 | +Screenshots are automatically captured and compared: |
| 55 | +```bash |
| 56 | +# Update snapshots when UI changes are intentional |
| 57 | +pnpm --filter e2e-frontend test:update-snapshots |
| 58 | +``` |
| 59 | + |
| 60 | +### Accessibility Testing |
| 61 | +Uses `@axe-core/playwright` for automated a11y checks. |
| 62 | + |
| 63 | +### Page Object Pattern |
| 64 | +Reusable page objects in `pages/` directory for maintainable tests. |
| 65 | + |
| 66 | +## Debugging |
| 67 | + |
| 68 | +### Local Debugging |
| 69 | +```bash |
| 70 | +# Run with browser visible |
| 71 | +pnpm --filter e2e-frontend test:headed |
| 72 | + |
| 73 | +# Step through with Playwright Inspector |
| 74 | +pnpm --filter e2e-frontend test:debug |
| 75 | + |
| 76 | +# Interactive test runner |
| 77 | +pnpm --filter e2e-frontend test:ui |
| 78 | +``` |
| 79 | + |
| 80 | +### CI Debugging |
| 81 | +- Playwright reports and videos are uploaded as artifacts |
| 82 | +- Check the "Artifacts" section in failed GitHub Action runs |
| 83 | +- Download and view the HTML report locally |
| 84 | + |
| 85 | +## Environment Variables |
| 86 | + |
| 87 | +The tests use these environment variables: |
| 88 | +- `NEXTAUTH_SECRET` - Required for authentication |
| 89 | +- `NODE_ENV=test` - Set automatically in CI |
| 90 | +- `CI=true` - Enables CI-specific behavior |
| 91 | + |
| 92 | +## Troubleshooting |
| 93 | + |
| 94 | +### Common Issues |
| 95 | + |
| 96 | +1. **Frontend not ready:** Increase timeout in CI if the app takes longer to start |
| 97 | +2. **Flaky tests:** Check for race conditions, add proper waits |
| 98 | +3. **Screenshot differences:** Update snapshots after intentional UI changes |
| 99 | + |
| 100 | +### Useful Commands |
| 101 | + |
| 102 | +```bash |
| 103 | +# Show test report after running tests |
| 104 | +pnpm --filter e2e-frontend test:report |
| 105 | + |
| 106 | +# Run specific test file |
| 107 | +pnpm exec playwright test home.spec.ts |
| 108 | + |
| 109 | +# Run tests matching pattern |
| 110 | +pnpm exec playwright test --grep "login" |
| 111 | +``` |
0 commit comments