본문으로 건너뛰기

10.3 Reporter와 Attachment

Reporter는 test 결과를 사람과 시스템이 소비하는 형식으로 변환합니다. Local terminal, CI log, shard merge, 장기 trend는 서로 다른 output을 요구합니다.

Reporter가 terminal, HTML, blob artifact로 나뉘는 화면

Built-in reporter 선택

Reporter장점대표 사용처
listtest와 step을 읽기 쉬움local, 작은 CI
dotlog가 짧음큰 CI
line진행 상황이 한 줄로 갱신interactive terminal
htmlfilter, error, attachment 탐색실패 분석
json/junitmachine integrationdashboard, test management
blobshard 결과를 손실 없이 mergedistributed 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를 구현합니다.

실습

  1. Local은 list, CI는 dot+blob+html로 구성합니다.
  2. Network mock payload를 attachment로 남깁니다.
  3. 실패 screenshot과 attachment에 secret이 없는지 검사합니다.
  4. 두 번 실행한 blob report를 한 HTML report로 merge합니다.

참고: Reporters, Reporter API