10.3 Reporter와 Attachment
Reporter는 test 결과를 사람과 시스템이 소비하는 형식으로 변환합니다. Local terminal, CI log, shard merge, 장기 trend는 서로 다른 output을 요구합니다.
Built-in reporter 선택
| Reporter | 장점 | 대표 사용처 |
|---|---|---|
list | test와 step을 읽기 쉬움 | local, 작은 CI |
dot | log가 짧음 | 큰 CI |
line | 진행 상황이 한 줄로 갱신 | interactive terminal |
html | filter, error, attachment 탐색 | 실패 분석 |
json/junit | machine integration | dashboard, test management |
blob | shard 결과를 손실 없이 merge | distributed CI |
reporter: process.env.CI
? [['dot'], ['blob'], ['html', { open: 'never' }]]
: [['list', { printSteps: true }], ['html', { open: 'never' }]],
Attachment
await testInfo.attach('request.json', {
body: JSON.stringify({ method: 'GET', path: '/api/summary' }, null, 2),
contentType: 'application/json',
});
Path attachment는 file이 존재하는 동안 reporter가 복사할 수 있게 await합니다.
await testInfo.attach('export.csv', {
path: testInfo.outputPath('export.csv'),
contentType: 'text/csv',
});
무엇을 붙일 것인가
- 실패와 직접 관련된 request/response의 sanitized subset
- 제품 상태를 설명하는 business ID
- Console error와 page error
- Accessibility scan summary
- Download 결과의 작은 fixture
모든 network body를 무조건 붙이면 report size, 개인정보, secret 노출 위험이 커집니다.
Shard report merge
각 shard가 blob report를 생성하고 마지막 job이 이를 모아 HTML report로 변환합니다.
npx playwright merge-reports --reporter html ./all-blob-reports
모든 shard는 같은 Playwright version과 compatible configuration을 사용해야 합니다. Artifact name에 shard index를 포함해 overwrite를 막습니다.
Custom reporter를 만들 시점
Built-in JSON/JUnit output을 downstream에서 변환할 수 있다면 custom reporter보다 결합도가 낮습니다. Test lifecycle 중 즉시 알림, 조직 전용 metadata, 결과 상태 override가 정말 필요할 때 Reporter API를 구현합니다.
실습
- Local은
list, CI는dot+blob+html로 구성합니다. - Network mock payload를 attachment로 남깁니다.
- 실패 screenshot과 attachment에 secret이 없는지 검사합니다.
- 두 번 실행한 blob report를 한 HTML report로 merge합니다.
참고: Reporters, Reporter API