Tracing
Playwrightトレースを収集・保存するためのAPIです。Playwrightスクリプトの実行後、Playwrightトレースはトレースビューアで開くことができます。
アクションを実行する前にトレースの記録を開始します。最後に、トレースを停止してファイルに保存します。
- 同期
- 非同期
browser = chromium.launch()
context = browser.new_context()
context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://playwright.dokyumento.jp")
context.tracing.stop(path = "trace.zip")
browser = await chromium.launch()
context = await browser.new_context()
await context.tracing.start(screenshots=True, snapshots=True)
page = await context.new_page()
await page.goto("https://playwright.dokyumento.jp")
await context.tracing.stop(path = "trace.zip")
メソッド
group
追加バージョン: v1.49利用可能な場合は、代わりにtest.step
を使用してください。
トレース内に新しいグループを作成し、tracing.group_end()が呼び出されるまで、後続のAPI呼び出しをこのグループに割り当てます。グループはネスト可能で、トレースビューアで表示されます。
使用法
- 同期
- 非同期
# All actions between group and group_end
# will be shown in the trace viewer as a group.
page.context.tracing.group("Open Playwright.dev > API")
page.goto("https://playwright.dokyumento.jp/")
page.get_by_role("link", name="API").click()
page.context.tracing.group_end()
# All actions between group and group_end
# will be shown in the trace viewer as a group.
await page.context.tracing.group("Open Playwright.dev > API")
await page.goto("https://playwright.dokyumento.jp/")
await page.get_by_role("link", name="API").click()
await page.context.tracing.group_end()
引数
-
トレースビューアに表示されるグループ名。
-
トレースビューアに表示されるグループのカスタム位置を指定します。デフォルトはtracing.group()呼び出しの位置です。
戻り値
group_end
追加バージョン: v1.49tracing.group()によって作成された最後のグループを閉じます。
使用法
tracing.group_end()
戻り値
start
追加バージョン: v1.12トレースを開始します。
使用法
- 同期
- 非同期
context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://playwright.dokyumento.jp")
context.tracing.stop(path = "trace.zip")
await context.tracing.start(screenshots=True, snapshots=True)
page = await context.new_page()
await page.goto("https://playwright.dokyumento.jp")
await context.tracing.stop(path = "trace.zip")
引数
-
指定された場合、中間トレースファイルは、browser_type.launch()で指定されたtraces_dirディレクトリ内の、指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stop()に
path
オプションを渡す必要があります。 -
トレース中にスクリーンショットをキャプチャするかどうか。スクリーンショットはタイムラインプレビューの作成に使用されます。
-
このオプションがtrueの場合、トレースは以下を実行します。
- すべてのアクションでDOMスナップショットをキャプチャします
- ネットワークアクティビティを記録します
-
sources
bool (任意)追加バージョン: v1.17#トレースアクションのソースファイルを含めるかどうか。
-
トレースビューアに表示されるトレース名。
戻り値
start_chunk
追加バージョン: v1.15新しいトレースチャンクを開始します。同じBrowserContextで複数のトレースを記録したい場合は、まずtracing.start()を使用し、その後tracing.start_chunk()とtracing.stop_chunk()で複数のトレースチャンクを作成します。
使用法
- 同期
- 非同期
context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://playwright.dokyumento.jp")
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")
await context.tracing.start(screenshots=True, snapshots=True)
page = await context.new_page()
await page.goto("https://playwright.dokyumento.jp")
await context.tracing.start_chunk()
await page.get_by_text("Get Started").click()
# Everything between start_chunk and stop_chunk will be recorded in the trace.
await context.tracing.stop_chunk(path = "trace1.zip")
await context.tracing.start_chunk()
await page.goto("http://example.com")
# Save a second trace file with different actions.
await context.tracing.stop_chunk(path = "trace2.zip")
引数
-
指定された場合、中間トレースファイルは、traces_dirディレクトリ内に、browser_type.launch()で指定された名前のプレフィックスを持つファイルとして保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stop_chunk()に
path
オプションを渡す必要があります。 -
トレースビューアに表示されるトレース名。
戻り値
stop
追加バージョン: v1.12トレースを停止します。
使用法
tracing.stop()
tracing.stop(**kwargs)
引数
-
path
Union[str, pathlib.Path] (任意)#指定されたパスにトレースをファイルとしてエクスポートします。
戻り値
stop_chunk
追加バージョン: v1.15トレースチャンクを停止します。複数のトレースチャンクに関する詳細は、tracing.start_chunk()を参照してください。
使用法
tracing.stop_chunk()
tracing.stop_chunk(**kwargs)
引数
-
path
Union[str, pathlib.Path] (任意)#最後のtracing.start_chunk()呼び出し以降に収集されたトレースを、指定されたパスにファイルとしてエクスポートします。
戻り値