Học Playwright tiếng Việt, Cộng đồng Playwright cho người Việt

Vọc Vạch Playwright

[Vọc Playwright] – Record video

https://playwright.dev/docs/videos

Introduction

  • Với Playwright, bạn có thể record video cho các test của bạn

Record video

  • Playwright Test có thể record video cho các test của bạn, controlled bởi các option của video trong file config. Mặc định video sẽ là off
    • off: Không record
    • on: Record video cho mỗi test
    • retain-on-failure: Record video cho mỗi test, nhưng xoá tất cả video của các test thành công
    • on-first-retry: Record video chỉ khi test bị thất bại lần đầu tiên
  • File video sẽ xuất hiện trong thư mục đầu ra test, thường là test-results. Xem testOptions.video để biết thêm config nâng cao
  • Video được lưu khi browser context đóng vào cuối 1 test. Nếu bạn tạo browser context 1 cách thủ công, hãy đảo bảo chờ browserContext.close() hoàn thành
import { defineConfig } from '@playwright/test';
export default defineConfig({
  use: {
    video: 'on-first-retry',
  },
});
const context = await browser.newContext({ recordVideo: { dir: 'videos/' } });
// Make sure to await close, so that videos are saved.
await context.close();
  • Bạn có thể chỉ định video size. Video size default là size viewport thu nhỏ xuống cho vừa 800×800. Video của viewport được đặt ở góc bên trái của video đầu ra, thu nhỏ xuống cho vừa nếu cần. Bạn có thể cần phải đặt viewport size phù hợp với video size mong muốn
import { defineConfig } from '@playwright/test';
export default defineConfig({
  use: {
    video: {
      mode: 'on-first-retry',
      size: { width: 640, height: 480 }
    }
  },
});
const context = await browser.newContext({
  recordVideo: {
    dir: 'videos/',
    size: { width: 640, height: 480 },
  }
});
  • Đối với multi-page scenarios, bạn có thể truy cập file video liên kết với trang thông qua page.video()
const path = await page.video().path();
  • Note: Video chỉ khả dụng khi trang hoặc browser context được đóng

Trả lời