截图与PDF
🌐 Screenshots & PDF
截图
🌐 Screenshots
| 命令 | 描述 |
|---|---|
screenshot | 截取视口截图 |
screenshot [target] | 截取特定元素截图 |
screenshot --filename=<f> | 使用自定义文件名保存 |
screenshot --type=<png|jpeg|webp> | 图片格式 |
screenshot --full-page | 截取整个可滚动页面,而不是视口 |
screenshot --hires | 捕获设备像素而不是 CSS 像素 |
如果没有 --filename,文件在输出目录中会被命名为 page-{timestamp}.{png|jpeg|webp}。当没有提供 --type 时,格式会根据文件扩展名推断,默认为 PNG。
🌐 Without --filename, the file is named page-{timestamp}.{png|jpeg|webp} in the output directory.
The format is inferred from the filename extension when --type is not given, and defaults to PNG.
$ playwright-cli screenshot
# Screenshot saved to .playwright-cli/page-2026-03-15T10-22-01-118Z.png
$ playwright-cli screenshot e15
# Screenshot of element e15
$ playwright-cli screenshot --filename=login-page.png
$ playwright-cli screenshot --full-page --filename=full-page.png
$ playwright-cli screenshot --filename=preview.jpeg
$ playwright-cli screenshot --hires --filename=retina.png
--hires 考虑了设备像素比,这使得在捕获的设计审查中,文字清晰可读——但它的像素坐标不再与 鼠标命令 使用的 CSS 像素坐标对齐。
PDF 导出
🌐 PDF export
playwright-cli pdf # save as page-{timestamp}.pdf
playwright-cli pdf --filename=page.pdf # save with custom name
何时使用截图
🌐 When to use screenshots
截图补充了辅助功能快照:
🌐 Screenshots complement accessibility snapshots:
| 用例 | 最佳工具 |
|---|---|
| 与元素交互 | 辅助功能快照(引用) |
| 验证视觉布局 | 截图 |
| 画布/图表内容 | 截图 |
| 记录错误 | 截图 |
| 了解页面结构 | 辅助功能快照 |
| 阅读文本内容 | 辅助功能快照 |
快照
🌐 Snapshots
用于辅助功能树输出(不是视觉捕获):
🌐 For accessibility tree output (not a visual capture):
playwright-cli snapshot # full page snapshot
playwright-cli snapshot --filename=f # custom filename
playwright-cli snapshot [target] # element snapshot
playwright-cli snapshot --depth=N # limit depth
playwright-cli snapshot --boxes # include bounding boxes
playwright-cli find "text" # search instead of capturing
有关格式和用法的详细信息,请参见 Snapshots。
🌐 See Snapshots for details on the format and usage.