본문으로 건너뛰기

12.2 CLI, Config Cheat Sheet

설치

npm init playwright@latest
npx playwright install chromium
npx playwright install --with-deps chromium

--with-deps는 주로 Linux CI에서 browser system dependency까지 설치할 때 사용합니다.

실행 범위

npx playwright test
npx playwright test tests/todo.spec.ts
npx playwright test tests/todo.spec.ts:12
npx playwright test --grep @smoke
npx playwright test --grep-invert @visual
npx playwright test --project=chromium
npx playwright test --workers=1
npx playwright test --repeat-each=20
npx playwright test --last-failed

Debug

npx playwright test --ui
npx playwright test --debug
npx playwright test --headed
npx playwright test --trace on
npx playwright show-trace test-results/.../trace.zip
npx playwright show-report

Snapshot

npx playwright test --update-snapshots
npx playwright test --update-snapshots --update-source-method=patch

Baseline update 전 diff를 리뷰합니다.

Parallel과 shard

npx playwright test --workers=4
npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3
npx playwright merge-reports --reporter html ./all-blob-reports

Codegen

npx playwright codegen http://127.0.0.1:4173
npx playwright codegen --save-storage=auth.json https://example.test/login
npx playwright codegen --load-storage=auth.json https://example.test/dashboard

Generated code는 locator와 expected result의 초안으로 사용하고 test architecture는 직접 설계합니다.

핵심 config 위치

export default defineConfig({
testDir: './tests', // runner option
timeout: 30_000, // test timeout
expect: { timeout: 5_000 }, // assertion timeout
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html', { open: 'never' }]],
use: { // browser context/page option
baseURL: 'http://127.0.0.1:4173',
trace: 'on-first-retry',
},
});

Top-level runner option과 use 안의 browser option을 구분합니다.

Timeout 진단 순서

  1. 실패 message에서 test/action/assertion timeout 종류 확인
  2. Trace에서 마지막 성공 action 확인
  3. Locator strictness와 actionability 확인
  4. Network/API readiness 확인
  5. 제품 성능 문제인지 측정
  6. 원인을 이해한 뒤 필요한 timeout만 조정

참고: Command line, Configuration