8.3 KiB
Playwright
Modern web application automation testing environment built with Microsoft Playwright. Supports Chromium, Firefox, and WebKit browsers, providing a complete end-to-end testing solution.
✨ Key Features
- 🚀 Fast and Reliable: Uses Microsoft official Playwright v1.55.0 image
- 🌐 Multi-Browser Support: Supports Chromium, Firefox, and WebKit
- 🎯 Precise Testing: Web-first assertions with auto-waiting and retry
- 📊 Rich Reports: HTML test reports with tracing and screenshots
- 🔧 Highly Configurable: Flexible test configuration and environment settings
- 🛡️ Secure and Stable: Follows official security best practices
📋 System Requirements
- Docker environment
- 1Panel control panel
- At least 2GB available memory
🚀 Quick Start
1Panel Deployment
-
Search for "Playwright" in the 1Panel app store
-
Click install and configure the following parameters:
- Port: Web service access port (default: 3000)
- Browser Type: Choose default browser engine
- Headless Mode: Whether to enable headless mode
- Viewport Size: Browser viewport width and height
- User Agent: Custom browser user agent string
- User/Group ID: Container runtime user and group identifiers
-
Click confirm to install
Accessing the Service
After installation, you can access via:
- Management Interface:
http://your-server-ip:port/ - Test Reports:
http://your-server-ip:port/test-results/ - Test Files:
http://your-server-ip:port/tests/
⚙️ Configuration Guide
Browser Types
- Chromium: Google Chrome kernel, recommended choice
- Firefox: Mozilla Firefox engine
- WebKit: Safari kernel, suitable for mobile testing
Running Modes
- Headed Mode: Shows browser interface, suitable for debugging and development
- Headless Mode: Runs in background, suitable for CI/CD and production environments
Security Configuration
- User ID: Recommended to use non-root user (default: 1000)
- Group ID: Corresponding user group (default: 1000)
- Application automatically configures security sandbox and permissions
🧪 Usage Guide
Creating Tests
- Access the management interface
- Click "Generate Example Test" to generate sample tests
- Edit test files in the
/app/tests/directory - Write tests using TypeScript or JavaScript
Sample Test Code
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Check page title
await expect(page).toHaveTitle(/Playwright/);
// Click link
const getStarted = page.getByRole('link', { name: 'Get started' });
await getStarted.click();
// Verify URL change
await expect(page).toHaveURL(/.*intro/);
});
Running Tests
- Click "Run All Tests" in the management interface
- Or use command line:
npx playwright test - View the generated HTML report
Configuration File
The application automatically generates playwright.config.ts configuration file:
export default defineConfig({
testDir: './tests',
fullyParallel: true,
retries: 2,
reporter: [['html', { outputFolder: './test-results' }]],
use: {
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: devices['Desktop Chrome'] },
{ name: 'firefox', use: devices['Desktop Firefox'] },
{ name: 'webkit', use: devices['Desktop Safari'] },
],
});
📁 Directory Structure
/app/
├── tests/ # Test files directory
├── test-results/ # Test reports and results
├── config/ # Configuration files
├── projects/ # Project files
├── playwright.config.ts # Playwright configuration
├── package.json # Node.js dependencies
└── server.js # Web management interface
🔧 Advanced Features
Parallel Testing
- Supports multi-browser parallel execution
- Automatic test workload distribution
- CI/CD environment optimization
Test Tracing
- Automatically generates test execution traces
- Visualizes test steps and timeline
- Automatic screenshots on failure
Custom Configuration
- Supports custom Playwright configuration
- Flexible project settings
- Environment variable configuration
🔄 Custom Script Execution
The application uses a separated configuration file design, allowing you to easily replace and customize execution scripts:
Configuration File Location
All application configuration files are located in the config/ directory:
config/
├── package.json # Node.js dependency configuration
├── playwright.config.ts # Playwright test configuration
├── server.js # Web management interface server
└── start.sh # Application startup script
Replacing Custom Scripts
-
Replace Startup Script
# Edit startup script vi config/start.sh -
Replace Web Server
# Edit or replace server script vi config/server.js -
Add Custom Scripts
# Add custom scripts in config directory vi config/my-custom-script.js -
Modify Startup Logic
Edit
config/start.shto call your custom scripts:#!/bin/bash echo "🎭 Setting up Playwright Test Environment..." # Ensure directories exist mkdir -p tests test-results # Install dependencies echo "📦 Installing dependencies..." npm install # Install Playwright browsers echo "🌐 Installing Playwright browsers..." npx playwright install # Run your custom script echo "🔧 Running custom script..." node my-custom-script.js # Start server (optional) echo "🚀 Starting Playwright server..." node server.js
Applying Changes
After modifying configuration files, restart the container to apply changes:
# Restart application in 1Panel
# Or use Docker Compose command
docker-compose restart playwright
Custom Script Example
Create a simple custom test script config/my-test.js:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
console.log('Page Title:', await page.title());
await browser.close();
})();
Then call it in start.sh:
# Run custom test
echo "🧪 Running custom test..."
node my-test.js
Notes
- All custom scripts must be placed in the
config/directory - Container restart is required after modifications
- Maintain executable permissions for script files
- Follow Playwright security best practices
🐛 Troubleshooting
Common Issues
-
Container Startup Failure
- Check if memory is sufficient (at least 2GB)
- Confirm port is not in use
- View container logs
-
Test Execution Failure
- Check browser configuration
- Verify test file syntax
- Confirm network connection
-
Permission Issues
- Adjust user ID and group ID configuration
- Check file system permissions
- Confirm data volume mounting
Log Viewing
# View container logs
docker logs playwright
# Follow logs in real-time
docker logs -f playwright
📚 Learning Resources
🔗 Related Links
📄 License
This project follows the open source license of Playwright. For details, please refer to the official repository.
🤝 Contributing
Welcome to submit Issues and Pull Requests to help improve this application configuration.
