playwright文档说明

playwright官方文档翻译


跟踪查看器

跟踪查看器

Playwright Trace Viewer 是一个 GUI 工具,可让您探索记录的 Playwright 测试跟踪,这意味着您可以来回浏览测试的每个操作,并直观地查看每个操作期间发生的情况。

您将学习

  • 如何记录跟踪
  • 如何打开 HTML 报表
  • 如何打开跟踪查看器

记录跟踪[](https://playwright.dev/python/docs/trace-viewer-intro#recording-a-trace "Direct link to heading")

可以使用browser_context.tracingAPI 记录跟踪,如下所示:

  • 同步
browser = chromium.launch()
context = browser.new_context()

# Start tracing before creating / navigating a page.
context.tracing.start(screenshots=True, snapshots=True, sources=True)

page = context.new_page()
page.goto("https://playwright.dev")

# Stop tracing and export it into a zip archive.
context.tracing.stop(path = "trace.zip")

异步

browser = await chromium.launch()
context = await browser.new_context()

# Start tracing before creating / navigating a page.
await context.tracing.start(screenshots=True, snapshots=True, sources=True)

page = await context.new_page()
await page.goto("https://playwright.dev")

# Stop tracing and export it into a zip archive.
await context.tracing.stop(path = "trace.zip")

这将记录跟踪并将其放入名为的文件中。trace.zip

打开跟踪[](https://playwright.dev/python/docs/trace-viewer-intro#opening-the-trace "Direct link to heading")

您可以使用 Playwright CLI 或在trace.playwright.dev 的浏览器中打开保存的跟踪。

playwright show-trace trace.zip

查看跟踪[](https://playwright.dev/python/docs/trace-viewer-intro#viewing-the-trace "Direct link to heading")

通过单击每个操作或使用时间线悬停来查看测试的跟踪,并查看操作前后页面的状态。在测试的每个步骤中检查日志、源和网络。跟踪查看器会创建一个 DOM 快照,以便您可以与其完全交互、打开开发工具等。

Playwright Trace Viewer

页面列表

ITEM_HTML