Site logo

Cách tạo báo cáo test chi tiết với Playwright Reporting

5:00 read

Cách tạo báo cáo test chi tiết với Playwright Reporting

Trong quá trình kiểm thử tự động, việc tạo báo cáo kết quả test là một phần rất quan trọng để:

  • Theo dõi kết quả thực thi
  • Debug lỗi nhanh chóng
  • Chia sẻ kết quả với nhóm QA/DEV/Manager

Playwright hỗ trợ sẵn nhiều loại báo cáo như: HTML, JSON, JUnit XML, và có thể tích hợp với Allure Report để tạo báo cáo nâng cao.


1. Báo cáo mặc định của Playwright

Khi bạn chạy lệnh:

npx playwright test

Playwright sẽ hiển thị báo cáo trực tiếp trên terminal:

✓ 2 tests passed (1.2s)

Nếu bạn muốn xem báo cáo dạng HTML UI, bạn cần thêm --reporter như sau:

npx playwright test --reporter=html

Sau đó mở báo cáo:

npx playwright show-report

Mặc định, báo cáo HTML được lưu tại playwright-report/index.html.


2. Cấu hình reporter trong playwright.config.ts

Bạn có thể định nghĩa sẵn reporter trong file cấu hình:

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  reporter: [
    ['list'],               // Reporter mặc định trên terminal
    ['html', { open: 'never' }],  // Báo cáo HTML
    ['json', { outputFile: 'reports/report.json' }], // Báo cáo JSON
    ['junit', { outputFile: 'reports/report.xml' }], // Báo cáo XML (dùng cho CI/CD)
  ],
});
Reporter Mô tả
list Mặc định, in kết quả ra console
dot Gọn nhẹ, phù hợp CI
html Giao diện đẹp, trực quan
json Dễ dùng để xử lý bằng script
junit Chuẩn dùng phổ biến trong CI/CD

Yêu cầu đăng nhập

Vui lòng đăng nhập để truy cập nội dung này

Additional Resources

Course Guide

Comprehensive PDF guide with examples

GitHub Repository

Example code for all lessons

Discussion

Have a question about this lesson? Post it here and get answers from instructors and peers.