This directory contains Playwright end-to-end tests for the Next.js web application.
The e2e tests cover:
- Home Page (
home.spec.ts) - Tests for the main landing page across all locales - User Page (
user.spec.ts) - Tests for user-specific pages - API Routes (
api.spec.ts) - Tests for API endpoints - Navigation (
navigation.spec.ts) - Tests for navigation and routing - Accessibility (
accessibility.spec.ts) - Tests for accessibility features - Authentication (
auth.spec.ts) - Tests for sign-in and sign-out flows
# Run all tests
yarn test:e2e
# Run tests in UI mode (interactive)
yarn test:e2e:ui
# Run tests in headed mode (see browser)
yarn test:e2e:headed
# Debug tests
yarn test:e2e:debug
# View test report
yarn test:e2e:report# Run all e2e tests
yarn test:e2e
# Run tests in UI mode
yarn test:e2e:ui
# Run tests in headed mode
yarn test:e2e:headedThe Playwright configuration is in playwright.config.ts. Key settings:
- Base URL:
http://localhost:3000(configurable viaPLAYWRIGHT_TEST_BASE_URLenv var) - Test Directory:
./e2e - Browsers: Chromium, Firefox, WebKit
- Web Server: Automatically starts the Next.js dev server before tests
For authentication tests, you can configure test credentials:
TEST_USER_EMAIL- Email for test user (default:test@test.com)TEST_USER_PASSWORD- Password for test user (default:password)
Tests are organized by feature/page:
home.spec.ts- Home page testsuser.spec.ts- User page testsapi.spec.ts- API endpoint testsnavigation.spec.ts- Navigation and routing testsaccessibility.spec.ts- Accessibility testsauth.spec.ts- Authentication tests (sign-in/sign-out)
The helpers.ts file provides utility functions:
getLocalizedUrl(path, locale)- Get URL for a route with localegetHomeUrl(locale)- Get home page URLgetUserUrl(userId, locale)- Get user page URLwaitForPageLoad(page)- Wait for page to fully loadisElementVisible(page, selector)- Check if element is visiblet(key, locale)- Get translated text for a given locale
Tests use locale-specific translations from helpers.ts:
- English (
en): "Demo Features", "Internationalization (i18n)" - Czech (
cs): "Demo funkce", "Mezinárodní lokalizace (i18n)" - French (
fr): "Fonctionnalités de démonstration", "Internationalisation (i18n)"
import { test, expect } from '@playwright/test'
import { t, type SupportedLocale } from './helpers'
test('should display demo sections for locale en', async ({ page }) => {
const locale: SupportedLocale = 'en'
await page.goto(`/${locale}`)
// Use translated text for the locale
const demoFeaturesText = t('Demo Features', locale)
await expect(page.getByText(demoFeaturesText, { exact: false })).toBeVisible()
})Tests run for all supported locales: en, cs, fr. Tests are automatically parameterized for each locale where applicable and use locale-specific translations.
The tests are configured to:
- Run in parallel on CI
- Retry failed tests (2 retries on CI)
- Generate HTML reports
- Take screenshots on failure
- Collect traces on retry
- Use test IDs - Prefer
testIDattributes for stable selectors - Wait for elements - Always wait for elements before interacting
- Test across locales - Test key features across all supported locales
- Use translations - Use the
t()helper function for locale-specific text - Keep tests independent - Each test should be able to run in isolation
- Use page object pattern - For complex pages, consider extracting page objects
- Ensure the dev server is running or Playwright's webServer config will start it automatically
- Check that port 3000 is available
- Increase wait timeouts
- Use
waitForLoadState('networkidle')for pages with dynamic content - Check for race conditions in async operations
- Screenshots are automatically taken on test failure
- Videos can be enabled in
playwright.config.tsby settingvideo: 'on'
- Ensure translations match the actual locale files in
packages/app/locales/{locale}/messages.po - Update
helpers.tstranslations if new text is added to the app