A comprehensive Playwright testing framework base project with authentication support, multiple browser testing, and CI/CD integration.
- Multi-browser testing - Chromium, Firefox, and WebKit support
- Authentication handling - Automated login with storage state management
- Environment configuration - Flexible configuration via environment variables
- CI/CD ready - GitHub Actions workflows for automated testing
- HTML reporting - Beautiful test reports with screenshots and traces
- Parallel execution - Optimized for fast test runs
- TypeScript support - Full type safety and IntelliSense
- Node.js (version 18 or higher)
- npm or yarn package manager
-
Clone the repository
git clone <your-repo-url> cd playwrightbase
-
Install dependencies
npm install
-
Install Playwright browsers
npx playwright install --with-deps
-
Configure environment variables
Copy the example environment file:
cp .env.example .env
Update
.env
with your application details:BASE_URL=https://your-app-url.com LOGIN_USERNAME=your-username LOGIN_PASSWORD=your-password
# Run all tests
npm test
# Run tests with UI mode (interactive)
npm run test:ui
# Run tests in headed mode (visible browser)
npm run test:headed
# Run only authentication tests
npm run test:auth
# Show test report
npm run report
# Generate tests with Codegen
npm run codegen
The project includes two Playwright configuration files:
playwright.config.ts
- Main configuration for general testsplaywright.auth.config.ts
- Configuration for authenticated tests
The project supports automated authentication with storage state management:
- Configure your login credentials in
.env
- Run authentication setup:
npm run test:auth
- Authentication state is saved to
.auth/user.json
- Subsequent tests can reuse this authentication state
playwrightbase/
βββ .auth/ # Authentication storage states
βββ .github/
β βββ workflows/
β βββ playwright.yml # GitHub Actions CI/CD
βββ tests/
β βββ pages/ # Page Object Models
β β βββ LoginPage.ts # Login page object
β βββ auth.setup.ts # Authentication setup
β βββ *.spec.ts # Test files
βββ .env.example # Environment variables template
βββ playwright.config.ts # Main Playwright configuration
βββ playwright.auth.config.ts # Auth-specific configuration
βββ README.md
Variable | Description | Required |
---|---|---|
BASE_URL |
Base URL of the application under test | Yes |
LOGIN_URL |
Login page URL | For auth tests |
LOGIN_USERNAME |
Username for authentication | For auth tests |
LOGIN_PASSWORD |
Password for authentication | For auth tests |
- Timeout: 30 seconds per test
- Global timeout: 2.5 hours for entire test suite
- Retries: 2 retries on CI, 0 locally
- Parallel execution: Tests run in parallel by default
- Traces: Collected on first retry for debugging
- Screenshots: Captured only on failure
- Videos: Retained only on failure
The project includes GitHub Actions workflows for automated testing:
- test-base - Runs general tests across all browsers
- test-auth - Runs authenticated tests (requires secrets configuration)
Configure these secrets in your GitHub repository settings:
BASE_URL
- Your application URLLOGIN_USERNAME
- Username for authenticationLOGIN_PASSWORD
- Password for authentication
After each workflow run, HTML reports are uploaded as artifacts:
playwright-report-base
- General test reportsplaywright-report-auth
- Authentication test reports
import { test, expect } from '@playwright/test';
test('should perform basic action', async ({ page }) => {
await page.goto('/');
// Your test code here
});
import { LoginPage } from '../pages/LoginPage';
test('should login successfully', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('username', 'password');
// Assertions
});
For tests requiring authentication, use the storage state:
test.use({ storageState: '.auth/user.json' });
test('should access protected content', async ({ page }) => {
await page.goto('/protected-page');
// Test authenticated content
});
# Debug specific test
npx playwright test --debug tests/example.spec.ts
# Run tests in headed mode to see browser
npm run test:headed
# Use UI mode for interactive debugging
npm run test:ui
When tests fail, traces are automatically collected. View them:
npx playwright show-trace test-results/trace.zip
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Run tests locally (
npm test
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
If you encounter any issues or need help:
- Check the Playwright documentation
- Review existing issues in the repository
- Create a new issue with detailed information
To update Playwright to the latest version:
npm update @playwright/test
npx playwright install --with-deps
- Use page objects for better test organization
- Leverage Playwright's auto-waiting capabilities
- Write descriptive test names and assertions
- Use data-testid attributes for reliable element selection
- Keep authentication logic separate from test logic
- Regularly update dependencies for security and features