This package provides a shared end-to-end (E2E) testing framework using Playwright for Helfi Drupal projects. It includes common configurations, utilities, and best practices for writing reliable browser tests.
- Overview
- Project Structure
- Setup and Installation
- Configuration
- Key Components
- Writing Tests
- Updating the Shared Package
- Best Practices
The E2E testing framework is designed to:
- Provide a consistent testing environment across all Helfi instances
- Handle common setup/teardown tasks automatically
- Include reusable test utilities and helpers
- Support parallel test execution
- Generate comprehensive test reports
/
├── .env # Environment variables
├── package.json # NPM package configuration
├── playwright.config.ts # Base Playwright configuration
├── sites.config.ts # Multi-site configuration
├── tests/ # Test files
│ ├── common/ # Common tests for all sites
│ │ └── *.spec.ts
│ └── sites/ # Site-specific tests
│ └── {site-name}/
│ └── *.spec.ts
└── utils/ # Shared utilities
├── fetchJsonApiRequest.ts # API request helper
├── globalSetup.ts # Global test setup
├── globalTeardown.ts # Global test teardown
├── handlers.ts # Common page handlers
├── logger.ts # Logging utilities
└── storagePath.ts # Storage state management
-
Install Dependencies:
npm install
-
Environment Variables:
cp .env.example .env
Edit the env file to suit your needs.
-
Running Tests:
# Run all tests npm run test
-
Running Tests with just one worker can help with performance issues:
npx playwright test --workers=1
The base configuration (in playwright.config.ts) includes:
- Default timeouts and retries
- Common reporters (list and HTML)
- Standard viewport settings
- Automatic screenshot and video capture on failure
- Storage state management
Projects can extend and override these settings as needed.
- Runs once before all tests
- Handles authentication and session management
- Saves browser state to a storage file
- Manages cookie consent and dialogs
- Cleans up after test execution
- Removes temporary files
- Handles any necessary cleanup tasks
- Manages the storage state file location
- Handles cross-platform path resolution
- Ensures proper directory structure exists
- Provides typed HTTP request methods
- Handles JSON:API interactions
- Includes proper error handling and type safety
- Common page interaction patterns
- Cookie consent handling
- Dialog and alert management
- See
README.md.