Playwright CI Pipeline Smoke Tests

Run Playwright smoke flows inside a CI pipeline with a dedicated job, browser binary caching, retries for flaky steps, and artifact traces.

TypescriptCli Tooling

Code

typescriptsnippet
36 lines
// e2e/smoke.spec.ts
import { test, expect } from '@playwright/test';

test('visitor can search and open a result', async ({ page }) => {
  await page.goto('/search');

  await page.getByLabel('Search').fill('rate limiting');
  await page.getByRole('button', { name: 'Search' }).click();

  await expect(page.getByRole('listitem')).not.toHaveCount(0);
  await page.getByRole('link', { name: /rate/i }).first().click();
  await expect(page).toHaveURL(/\/examples\//);
});

test('health endpoint is green', async ({ request }) => {
  const res = await request.get('/healthz');
  expect(res.ok()).toBeTruthy();
  expect(await res.json()).toMatchObject({ status: 'up' });
});

// .github/workflows/smoke.yml(节选)
// smoke:
//   runs-on: ubuntu-latest
//   steps:
//     - uses: actions/checkout@v4
//     - run: corepack enable
//     - run: pnpm install --frozen-lockfile
//     - run: pnpm exec playwright install --with-deps chromium
//       env:
//         PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright
//     - run: pnpm exec playwright test --project=chromium --retries=2
//     - uses: actions/upload-artifact@v4
//       if: failure()
//       with:
//         name: traces
//         path: test-results/

Inside the snippet

Asynchronous boundaries use await, so failures surface as rejected promises at the call site instead of being swallowed. Reach for @playwright/test and what you get is test, expect — that is the whole API contact area.

Points of care

  • Plan for an install step: @playwright/test is a real dependency, resolved by the package manager.

Key statements

await page.getByRole('link', { name: /rate/i }).first().click();
await expect(page.getByRole('listitem')).not.toHaveCount(0);
await page.getByRole('button', { name: 'Search' }).click();

Interactive Tools for This Topic

FAQ

Does this require external packages?
Yes — `@playwright/test`. Add it to your project before running the snippet.