最强自动化测试框架Playwright (27)-跟踪查看器

Playwright Trace Viewer 是一个 GUI 工具,可帮助您在脚本运行后探索记录的 Playwright 跟踪。可以本地打开,也可以在trace.playwright.dev.打开,

录制跟踪文件

使用context.tracing.start进行录制,使用stop方法保存录制文件

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")

本地打开跟踪文件

使用命令即可打开

playwright show-trace trace.zip

在跟踪文件中,可以看到playwright执行的action

 如果screenshot选项为True,每个跟踪都会记录一个截屏视频并将其呈现为胶片,可以将鼠标悬停在胶片上以查看每个操作和状态的放大图像,有助于轻松找到要检查的操作。

创建多个跟踪文件

如果想使用同一个浏览器上下文创建多个跟踪文件,可以先用tracing.start()。然后再使用tracing.start_chunk创建多个跟踪文件。

context.tracing.start(name="trace", screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://playwright.dev")

context.tracing.start_chunk()
page.get_by_text("Get Started").click()
# Everything between start_chunk and stop_chunk will be recorded in the trace.
context.tracing.stop_chunk(path = "trace1.zip")

context.tracing.start_chunk()
page.goto("http://example.com")
# Save a second trace file with different actions.
context.tracing.stop_chunk(path = "trace2.zip")

trace网站打开

trace.playwright.dev是跟踪查看器的静态托管变体,可以使用拖放功能上传跟踪文件。

你可能感兴趣的:(#,playwright,自动化,测试)