Prompt
How do I use browser automation in CI/CD pipelines?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
Using browser automation in CI/CD usually means running end-to-end or UI tests against your app automatically on every push, pull request, or release. The core idea is:
- build your app
- start it in a test environment
- run browser tests headlessly
- collect reports/artifacts
- fail the pipeline if tests fail
Common browser automation tools
- Playwright — modern, reliable, easy to run headless in CI
- Cypress — popular for frontend testing, good DX
- Selenium/WebDriver — classic, broader ecosystem
- Puppeteer — great for Chromium-only automation
Typical CI/CD pattern
1) Install dependencies
Your pipeline should install:
- app dependencies
- browser automation dependencies
- browsers needed by the test runner
2) Start the application
Run your app server in the background or use a preview/deployment environment.
3) Wait for readiness
Before tests start, wait until the app is reachable:
- health endpoint
- simple HTTP check
- built-in CI wait step
4) Run tests headlessly
Execute tests with a headless browser so no GUI is needed.
5) Publish artifacts
Save:
- screenshots
- videos
- traces
- test reports
6) Fail fast on errors
If automation fails, mark the build as failed.
Example: Playwright in GitHub Actions
name: E2E Tests
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Build app
run: npm run build
- name: Start app
run: npm start &
- name: Wait for app
run: npx wait-on http://localhost:3000
- name: Run tests
run: npx playwright test
- name: Upload report
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
Example: Cypress in CI
- name: Start app
run: npm start &
- name: Run Cypress
run: npx cypress run
In practice, you often also:
- run the app on a fixed port
- use
start-server-and-test - store screenshots/videos as artifacts
Best practices
Keep tests stable
- avoid relying on exact timing
- use explicit waits for conditions, not arbitrary sleeps
- prefer stable selectors like
data-testid
Run headless
- use headless browsers in CI
- only use headed mode for debugging locally
Isolate test data
- reset DB state between runs
- use test fixtures
- run against disposable environments when possible
Parallelize
- split test suites to reduce CI time
- run tests in parallel when your tool supports it
Capture debugging info
- screenshots on failure
- video/trace on failure
- logs from app and browser
Use retries sparingly
- retries can reduce flakiness, but don’t hide real issues
- use them only for known intermittent failures
Match production-like conditions
- same browser versions if possible
- similar environment variables
- test against a staging environment that resembles prod
Common CI/CD challenges
- Flaky tests from timing issues or unstable selectors
- Slow builds due to browser downloads or many tests
- Environment differences between local and CI
- Authentication/setup complexity
- Network dependencies if tests hit real services
Recommended approach
If you’re starting fresh:
- use Playwright
- run tests in GitHub Actions or your CI platform
- use headless Chromium/Firefox/WebKit
- save traces and screenshots on failure
- test on every PR, but keep the suite small and reliable
If you want, I can give you a ready-to-use CI example for GitHub Actions, GitLab CI, or Jenkins with Playwright or Cypress.