CI GitHub Actions
Introduction
Playwright tests can be ran on any CI provider. In this section we will cover running tests on GitHub using GitHub actions. If you would like to see how to configure other CI providers check out our detailed doc on Continuous Integration.
To add a GitHub Actions file first create .github/workflows
folder and inside it add a playwright.yml
file containing the example code below so that your tests will run on each push and pull request for the main/master branch.
You will learn
Setting up GitHub Actions
On push/pull_request
Tests will run on push or pull request on branches main/master. The workflow will install all dependencies, install Playwright and then run the tests.
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@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- run: dotnet build
- name: Ensure browsers are installed
run: pwsh bin/Debug/net6.0/playwright.ps1 install --with-deps
- name: Run your tests
run: dotnet test
Via Containers
GitHub Actions support running jobs in a container by using the jobs.<job_id>.container
option. This is useful to not pollute the host environment with dependencies and to have a consistent environment for e.g. screenshots/visual regression testing across different operating systems.
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
playwright:
name: 'Playwright Tests'
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright/dotnet:v1.38.0-jammy
steps:
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- run: dotnet build
- name: Run your tests
run: dotnet test
On deployment
This will start the tests after a GitHub Deployment went into the success
state. Services like Vercel use this pattern so you can run your end-to-end tests on their deployed environment.
name: Playwright Tests
on:
deployment_status:
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- run: dotnet build
- name: Ensure browsers are installed
run: pwsh bin/Debug/net6.0/playwright.ps1 install --with-deps
- name: Run tests
run: dotnet test
env:
# This might depend on your test-runner
PLAYWRIGHT_TEST_BASE_URL: ${{ github.event.deployment_status.target_url }}
Create a Repo and Push to GitHub
Once you have your GitHub actions workflow setup then all you need to do is Create a repo on GitHub or push your code to an existing repository. Follow the instructions on GitHub and don't forget to initialize a git repository using the git init
command so you can add, commit and push your code.

Opening the Workflows
Click on the Actions tab to see the workflows. Here you will see if your tests have passed or failed.

On Pull Requests you can also click on the Details link in the PR status check.

Viewing Test Logs
Clicking on the workflow run will show you the all the actions that GitHub performed and clicking on Run Playwright tests will show the error messages, what was expected and what was received as well as the call log.

Viewing the Trace
trace.playwright.dev is a statically hosted variant of the Trace Viewer. You can upload trace files using drag and drop.
