持續整合
簡介
Playwright 測試可以在 CI 環境中執行。我們已經為常見的 CI 提供者建立了範例配置。
3 步驟讓你的測試在 CI 上執行:
-
確保 CI 代理可以執行瀏覽器: 在 Linux 代理中使用我們的 Docker 映像或使用CLI安裝您的相依套件。
-
安裝 Playwright:
pip install playwright
playwright install --with-deps -
執行您的測試:
pytest
CI configurations
命令列工具 可以用來在 CI 中安裝所有作業系統相依套件。
GitHub Actions
在 push/pull_request
測試將在 push 或 pull request 到 main/master 分支時執行。 工作流程 會安裝所有相依套件,安裝 Playwright,然後執行測試。
.github/workflows/playwright.yml
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Ensure browsers are installed
run: python -m playwright install --with-deps
- name: Run your tests
run: pytest --tracing=retain-on-failure
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-traces
path: test-results/