Prompt
How do I run browser-based regression tests in CI
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To run browser-based regression tests in CI, you typically:
-
Choose a browser automation tool
- Common options:
- Playwright (recommended for new projects)
- Cypress
- Selenium/WebDriver
- For regression testing, Playwright is often the easiest because it supports Chromium, Firefox, and WebKit with good CI support.
- Common options:
-
Make tests deterministic
- Seed test data
- Mock external APIs where possible
- Use stable selectors (
data-testid, ARIA labels) instead of brittle CSS/XPath - Avoid depending on timing; wait for specific UI states
-
Run in headless mode
- CI environments usually don’t have a display server
- Headless mode is standard for browser tests in CI
-
Set up CI to install dependencies and browsers
- Install app dependencies
- Install browser binaries
- Start any required backend/services
- Run tests after the app is up
-
Capture artifacts on failure
- Screenshots
- Videos
- Trace files/logs
- This helps debug flaky failures
Example: Playwright in CI
1) Install Playwright
npm install -D @playwright/test
npx playwright install --with-deps
2) Example test
import { test, expect } from '@playwright/test';
test('homepage loads', async ({ page }) => {
await page.goto('http://localhost:3000');
await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
});
3) GitHub Actions workflow
name: Browser Tests
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx playwright install --with-deps
- run: npm run build
- run: npm run start &
- run: npx wait-on http://localhost:3000
- run: npx playwright test
- name: Upload Playwright artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-artifacts
path: |
playwright-report
test-results
Best practices for regression tests in CI
- Run a smaller smoke suite on every PR, full regression nightly or on merge
- Parallelize tests to keep CI fast
- Use retries sparingly to reduce flaky failures, but don’t hide real issues
- Tag tests so you can split fast/slow or critical/noncritical suites
- Use ephemeral test environments if your app depends on backend state
- Reset DB/state between tests if tests mutate data
If you use Cypress instead
Cypress also works well in CI:
npm install -D cypress
npx cypress run
GitHub Actions example:
- run: npm ci
- run: npm run build
- run: npm start &
- run: npx wait-on http://localhost:3000
- run: npx cypress run
If you want, I can give you a ready-to-use CI config for GitHub Actions, GitLab CI, or Jenkins, or show the best setup for Playwright/Cypress in your stack.