Contributing
Testing Guide
Testing guidelines and setup for BetterGov
Testing
End-to-End Testing
This project uses Playwright for end-to-end testing to ensure critical user flows work correctly across different browsers and devices.
Running E2E Tests
npm run test:e2e
- Run all E2E tests headlesslynpm run test:e2e:ui
- Open Playwright UI to run and debug tests interactivelynpm run test:e2e:headed
- Run tests with visible browser windowsnpm run test:e2e:debug
- Debug tests with Playwright Inspectornpm run test:e2e:codegen
- Record new tests using Playwright's code generator
E2E Test Coverage
Our E2E tests cover:
-
Critical User Flows
- Homepage loading and navigation
- PhilSys National ID registration
- Government services search
- Language switching
- Emergency hotlines access
-
Navigation
- Main menu navigation
- Dropdown menus
- Footer links
- Breadcrumb navigation
-
Accessibility
- WCAG compliance checks using axe-core
- Keyboard navigation
- ARIA labels and alt text
- Focus indicators
-
Performance
- Page load times
- First Contentful Paint metrics
- DOM size optimization
- Image optimization
- Slow network handling
Writing E2E Tests
E2E tests are located in the e2e/
directory. Example test structure:
import { test, expect } from '@playwright/test';
test('user can search for services', async ({ page }) => {
await page.goto('/');
await page.getByPlaceholder(/Search for services/i).fill('passport');
await page.getByPlaceholder(/Search for services/i).press('Enter');
await expect(page).toHaveURL('/search');
await expect(page.locator('text=/passport/i')).toBeVisible();
});