The tests require a valid TMDB API key to load movie data.
Get your API key:
- Create account at https://www.themoviedb.org/
- Go to Settings → API
- Request API Key → Developer
- Copy your v3 API key
Configure the key:
# Create .env file from example
cp .env.example .env
# Edit .env and add your API key
VITE_API_KEY=your_actual_api_key_here
VITE_TMDB_API_BASE_URL=https://api.themoviedb.org/3# Install all dependencies
npm install
# Install Playwright browsers
npx playwright install --with-deps chromiumThe tests need the dev server running. Playwright will automatically start it, or you can run it manually:
npm run devnpm testnpm run test:uiThis opens the Playwright UI where you can:
- See tests running in real-time
- Step through tests
- Debug failures
- Watch network requests
npm run test:headednpm run test:reportIf you run tests without a valid .env file:
- 1 test will PASS: "should navigate to watchlist page and show empty state"
- 8 tests will SKIP: All tests requiring movie data
Example output without API key:
9 tests (8 skipped, 1 passed)
With a valid TMDB API key configured:
- All 9 tests should PASS ✅
- ✅ Navigation - Watchlist page loads and shows empty state
- ✅ Add from Home - Bookmark button adds movie to watchlist
- ✅ Remove - Confirmation dialog and removal works
- ✅ Change Status - Status dropdown persists changes
- ✅ Add Notes - Notes field saves on blur
- ✅ Filter by Status - Status filter shows correct items
- ✅ Export - JSON download works
- ✅ localStorage - Data structure is correct
- ✅ Add from Detail - Detail page bookmark works
npx playwright test --debugTests automatically generate traces on first retry. View them:
npx playwright show-trace trace.zip# By test name
npx playwright test -g "should add movie to watchlist"
# By file
npx playwright test e2e/watchlist/watchlist.spec.ts# Run in headed mode with slower execution
npx playwright test --headed --slowMo=1000Solution: Add TMDB API key to .env file
Possible causes:
- Invalid API key
- Network issues
- TMDB API is down
Solution:
# Check your API key is valid
curl "https://api.themoviedb.org/3/movie/popular?api_key=YOUR_KEY"Solution: The tests use robust selectors. If still failing:
- Run in UI mode to see what's happening
- Check if the component structure changed
- Use
--debugmode to inspect selectors
name: E2E Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Install Playwright
run: npx playwright install --with-deps chromium
- name: Create .env file
run: |
echo "VITE_API_KEY=${{ secrets.TMDB_API_KEY }}" > .env
echo "VITE_TMDB_API_BASE_URL=https://api.themoviedb.org/3" >> .env
- name: Run tests
run: npm test
- name: Upload test report
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/
retention-days: 30Required Secret:
- Add
TMDB_API_KEYto your GitHub repository secrets
| Feature | Tested | Details |
|---|---|---|
| Navigation | ✅ | Watchlist link, empty state |
| Add/Remove | ✅ | From home, detail pages |
| Status Tracking | ✅ | Dropdown, persistence |
| Notes | ✅ | Add, edit, persist |
| Filtering | ✅ | All, Want to Watch, Watching, Watched |
| Export | ✅ | JSON file download |
| Persistence | ✅ | localStorage structure & reload |
9 tests total, 100% pass rate
- Visual Regression Tests
npm install -D @playwright/test-visual- Accessibility Tests
npm install -D axe-playwright- Mobile Testing Add mobile viewport tests:
test.use({ viewport: { width: 375, height: 667 } });- Performance Testing
test('should load watchlist page fast', async ({ page }) => {
const start = Date.now();
await page.goto('/watchlist');
const loadTime = Date.now() - start;
expect(loadTime).toBeLessThan(2000);
});If tests fail unexpectedly:
- Check
.envfile exists and has valid API key - Run
npm run test:uito see visual feedback - Check browser console in headed mode
- Review test report:
npm run test:report