Prompt
How do I automate browser jobs in CI/CD so they run on every pull request?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To automate browser jobs in CI/CD on every pull request, the common pattern is:
- Write browser tests
- Run them in headless mode
- Trigger them from your CI on PR events
- Upload artifacts on failure so you can debug
Typical setup
1) Pick a browser automation tool
Common choices:
- Playwright — best modern default
- Cypress — great DX, popular for web apps
- Selenium/WebDriver — good for broad compatibility
- Puppeteer — mostly Chrome-specific
If you’re starting fresh, Playwright is usually the easiest for CI.
2) Make sure tests can run headlessly
CI servers usually have no GUI, so tests should run without a visible browser.
Example for Playwright:
npx playwright test
Example for Cypress:
npx cypress run
3) Add a CI workflow for pull requests
GitHub Actions example with Playwright
Create .github/workflows/browser-tests.yml:
name: Browser Tests
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Run tests
run: npx playwright test
- name: Upload test report on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report
4) Configure CI to fail the PR if tests fail
This happens automatically if your workflow exits non-zero. Most CI systems will mark the check failed, and you can require that check before merging.
In GitHub:
- Go to Branch protection rules
- Require the browser test workflow to pass before merge
5) Save useful artifacts
For debugging, upload:
- screenshots
- videos
- HTML reports
- logs
Playwright can be configured to capture these automatically:
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
screenshot: 'only-on-failure',
video: 'retain-on-failure',
trace: 'retain-on-failure',
},
});
If you use Cypress
Example GitHub Actions workflow:
name: Cypress Tests
on:
pull_request:
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npx cypress run
- name: Upload screenshots/videos
if: failure()
uses: actions/upload-artifact@v4
with:
name: cypress-artifacts
path: |
cypress/screenshots
cypress/videos
Best practices
- Run only a smoke subset on every PR, and run the full suite nightly or on merge to main
- Use stable selectors like
data-testid - Keep tests independent from each other
- Spin up the app in CI before tests run
- Mock external services where possible
- Use retries sparingly to reduce flaky failures, but don’t hide real issues
Example of starting your app in CI:
- run: npm run build
- run: npm run start &
- run: npx wait-on http://localhost:3000
- run: npx playwright test
If you tell me your stack, I can generate a ready-to-use CI file
For example:
- GitHub Actions + Playwright
- GitLab CI + Cypress
- Jenkins + Selenium
- Azure DevOps + Playwright
If you want, I can give you a copy-paste workflow for your exact setup.