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.
Code
// 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/testis 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
Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Tar Archive Command BuilderBuild safe tar create, extract, and list commands for gzip, xz, zstd, and bzip2 archives with excludes, target directory (-C), and flag explanations.
FAQ
- Does this require external packages?
- Yes — `@playwright/test`. Add it to your project before running the snippet.
Report a problem with this exampleOpens a pre-filled issue on GitHub.