Playwright: Chụp Screenshot & Đính Kèm vào HTML Report
5:00 read
Playwright: Chụp Screenshot & Đính Kèm vào HTML Report
1. Tổng quan
Playwright cung cấp hai cách để lưu screenshot trong E2E test:
| Cách | Mô tả | Hiện trong report? |
|---|---|---|
page.screenshot({ path }) |
Lưu file ảnh ra disk | Không (phải tự mở file) |
testInfo.attach() |
Đính kèm vào HTML report | Có — hiện trong tab Attachments |
Bài này hướng dẫn kết hợp cả hai: lưu file ra disk và đính kèm vào report để dễ xem nhất.
2. Cài đặt
pnpm add -D @playwright/test
pnpm add dotenv
Cấu hình playwright.config.ts:
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
reporter: 'html',
use: {
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
});
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.
