Skip to content

Recording Pest browser tests in GitHub Actions

Record selected Pest browser tests on pull requests and publish videos to Diff Stage with a two-job GitHub Actions workflow and OIDC authentication.

Guide 2 of 45 min readPest 5 · Browser 5.1.2 · PHP 8.5

On this page

Before you start

This example uses Pest 5, Browser 5.1.2, PHP 8.5 and Playwright 1.63.0.

Start with your working browser-test CI. Reuse its Docker image, services, test environment, database, fixtures and asset build. Record evidence at the pull request's head commit, and publish from a separate trusted job. Diff Stage posts a player link on the PR so reviewers can watch the change.

Choose a useful browser journey#

Use a test that reaches the changed behaviour, performs the relevant interaction and asserts the visible outcome. Keep the full regression suite in its own jobs.

For example, a change to a checkout message needs a checkout journey. A homepage smoke test can't prove that change. Prefer existing scenarios that prove the change. You can select two scenarios from a file with many tests without moving them into new files.

File-only selection runs every test in a file:

Terminalshell
./vendor/bin/pest tests/Browser/CheckoutTest.php --record-videos

--record-videos-only limits which tests are recorded, not which tests run. Don't add arbitrary waits to make footage readable. The recorder and hosted processing provide reading time.

Save the workflow#

Adapt this job structure to your existing workflow. Run diff-stage-record in the same container where Pest already works. Pass the selection JSON into that container, and copy its videos back for the artifact upload. Keep your existing app setup. If you have no browser CI, save this standalone example as .github/workflows/browser-evidence.yml. The example assumes committed Composer and npm lockfiles, Playwright in package.json, a Vite build and SQLite-compatible migrations.

.github/workflows/browser-evidence.ymlyaml
name: Browser evidence

on:
  pull_request:
    types: [opened, synchronize, reopened]

permissions:
  contents: read

concurrency:
  group: browser-evidence-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  preflight:
    if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    outputs:
      tests: ${{ steps.preflight.outputs.tests }}
      selection: ${{ steps.preflight.outputs.selection }}
    steps:
      - id: preflight
        uses: diff-stage/recorder/preflight@abde5f2be779cb5dc7ba179be683edc2d5c55906

  record:
    needs: preflight
    if: needs.preflight.outputs.tests != ''
    runs-on: ubuntu-latest
    permissions:
      contents: read
    env:
      APP_ENV: testing
      APP_DEBUG: 'false'
      DB_CONNECTION: sqlite
      DB_DATABASE: ${{ github.workspace }}/database/database.sqlite
      DB_URL: ''
      FILESYSTEM_DISK: local
      CACHE_STORE: array
      SESSION_DRIVER: array
      MAIL_MAILER: array
      QUEUE_CONNECTION: sync
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          persist-credentials: false
      - uses: shivammathur/setup-php@b604ade2a87db23f8871b7182e69ec5e75effb45 # v2
        with:
          php-version: '8.5'
          extensions: pdo_sqlite, sockets
          coverage: none
      - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
        with:
          node-version: '24'
      - name: Prepare Laravel and Playwright
        run: |
          composer install --no-interaction --prefer-dist
          cp .env.example .env
          php artisan key:generate --no-interaction
          touch database/database.sqlite
          php artisan migrate --force --no-interaction
          npm ci
          npx --no-install playwright install --with-deps chromium
          npm run build
      - name: Record selected flows
        env:
          SELECTION: ${{ needs.preflight.outputs.selection }}
        run: |
          rm -rf tests/Browser/Videos
          mkdir -p tests/Browser/Videos
          git rev-parse HEAD > tests/Browser/Videos/sha.txt
          printf '%s\n' "$SELECTION" > .diff-stage-selection.json
          php vendor/diff-stage/recorder/bin/diff-stage-record .diff-stage-selection.json --record-videos-fast
      - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
        with:
          name: browser-videos-${{ github.event.pull_request.head.sha }}
          path: tests/Browser/Videos
          if-no-files-found: error
          retention-days: 7

  publish:
    needs: [preflight, record]
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      id-token: write
    steps:
      - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
        with:
          name: browser-videos-${{ github.event.pull_request.head.sha }}
          path: tests/Browser/Videos
      - name: Check recording provenance
        env:
          HEAD_SHA: ${{ github.event.pull_request.head.sha }}
        run: |
          [[ "$(cat tests/Browser/Videos/sha.txt)" == "$HEAD_SHA" ]]
          compgen -G 'tests/Browser/Videos/*.webm' >/dev/null
      - uses: diff-stage/recorder/publish@abde5f2be779cb5dc7ba179be683edc2d5c55906
        with:
          selection: ${{ needs.preflight.outputs.selection }}

The recording job checks out the PR's head SHA and runs without publishing rights. The publishing job downloads that job's artifact and checks its recorded SHA before upload. It never checks out or runs application code.

A trusted preflight job checks publication access and reads the tests named for the branch before the workflow prepares the app. It has id-token: write and never checks out repository code. The recording job runs only if preflight succeeds and finds named tests. The publisher also has id-token: write, plus permission to comment on the PR. The recording job has neither permission. GitHub Actions identity authenticates the upload to the connected repository, so you don't need an upload secret. See GitHub's OIDC documentation.

Name the tests that prove the change#

On the PR branch, before pushing, name each existing test with its file and full Pest name:

Name a testshell
vendor/bin/diff-stage-show "tests/Browser/WizardTest.php::it saves a draft" \
    --why "Drafts now keep the uploaded logo. Watch it reappear after reload."

The command checks that Pest finds the test and saves it on Diff Stage for the branch. The first time, it opens your browser to approve the sign-in. Your agent skill does this for you. On each push, preflight passes the branch's named tests as its selection JSON output. The workflow saves that output and runs php vendor/diff-stage/recorder/bin/diff-stage-record inside your existing test environment. Don't add a PR-specific filter to CI.

Names are literal, including spaces, commas and regex characters. Include the it prefix for it() tests, and include any describe groups. A data-driven test records all its dataset variants under one note. Name only the file to record every test in it. Changed files aren't added automatically.

The note is what the PR comment says about that test's videos. Nothing goes in your commits or PR description. If no browser journey shows the change, name nothing and explain in the PR how you verified it. This skips evidence recording and publication. Your separate regression jobs still run.

Check the published result#

Open the workflow run. The preflight, record and publish jobs must all succeed. Then open the Diff Stage comment, check that its commit matches the PR head and play every selected recording. Fast recordings may still be processing after CI finishes.

Fork and Dependabot PRs skip preflight, so this workflow doesn't record them.

To compare a PR against approved behaviour, record the same existing scenarios on your default branch and publish with mode: baseline. Keep that recording job separate from the publisher too. Use a push trigger for your actual default branch, write its checked-out SHA to sha.txt, and publish only after recording succeeds. Keep all baseline recordings in one workflow so github.run_number orders them consistently.

The baseline can record the selected scenarios with a checked-in JSON selection and diff-stage-record, or record their whole files. Reuse the same Docker and browser environment. Scenario selection keeps the existing flow keys. For a whole-file baseline, the recording step can be:

Baseline recording stepshell
rm -rf tests/Browser/Videos
mkdir -p tests/Browser/Videos
git rev-parse HEAD > tests/Browser/Videos/sha.txt
./vendor/bin/pest tests/Browser --record-videos --record-videos-fast

After the baseline publisher downloads and verifies that artifact, its final step is:

Baseline publish stepyaml
- uses: diff-stage/recorder/publish@abde5f2be779cb5dc7ba179be683edc2d5c55906
  with:
    mode: baseline
    url: https://diffstage.com

Next, compare the recordings before merging.

Troubleshooting#

  • Recording is skipped. Run vendor/bin/diff-stage-show on the branch to list what it names. Tests named after your latest push record on the next push or when you re-run the workflow. An empty selection skips publication, which is expected.
  • Preflight fails. Connect this exact repository to an active Diff Stage GitHub App installation and check the team plan. Preflight checks current access, and publishing checks it again after recording.
  • Upload authentication fails. Check the repository's GitHub App connection, the team plan and id-token: write on the publisher. Upload tokens aren't supported.
  • SHA mismatch. Rerun recording for the current PR head. Don't edit sha.txt to make older footage pass the check.
  • CI passes but no player is ready. Check the publisher result and Diff Stage's processing status. An artifact alone isn't a hosted recording.
  • A previous comment remains. Check its SHA. Removing the evidence selection doesn't turn an older recording into evidence for the new commit.

Show your reviewers what changed

Add the recorder to your test suite, and your next pull request gets a video.