Câu hỏi phỏng vấn #18: Cách integrate Playwright với CI/CD pipeline?
Trả lời mẫu:
1. GitHub Actions:
name: Playwright Tests
on: [push, pull_request]
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - name: Install dependencies run: npm ci - name: Install Playwright run: npx playwright install --with-deps - name: Run tests run: npx playwright test - uses: actions/upload-artifact@v3 if: always() with: name: playwright-report path: playwright-report/
2. Docker setup:
FROM mcr.microsoft.com/playwright:v1.40.0-focal
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npx", "playwright", "test"]
3. GitLab CI:
playwright: image: mcr.microsoft.com/playwright:v1.40.0-focal script: - npm ci - npx playwright test artifacts: when: always paths: - playwright-report/ expire_in: 30 days
4. Jenkins Pipeline:
pipeline { agent { docker { image 'mcr.microsoft.com/playwright:v1.40.0-focal' } } stages { stage('Test') { steps { sh 'npm ci' sh 'npx playwright test' } } } post { always { publishHTML([reportDir: 'playwright-report', reportFiles: 'index.html']) } }
}
5. Parallel execution in CI:
#Sharding across multiple jobs
npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
💡 Tips:
- Use official Playwright Docker images
- Cache node_modules và browser binaries
- Upload test reports as artifacts
- Run tests in parallel với sharding
- Set up retry policies cho flaky tests
Lời Kết
Playwright đang trở thành một trong những automation frameworks phổ biến nhất cho web testing. Thông qua series này, hy vọng bạn sẽ:
- Nắm vững kiến thức từ cơ bản đến nâng cao
- Tự tin trong các buổi phỏng vấn
- Áp dụng hiệu quả vào dự án thực tế
- Trở thành một phần của cộng đồng Playwright Việt Nam năng động
📚 Bắt đầu hành trình của bạn với: Bài 1: Playwright vs Selenium
💬 Có câu hỏi? Tham gia group Facebook của chúng mình!
⭐ Theo dõi series để không bỏ lỡ bài viết mới!