トレーシング
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.49で追加tracing.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スナップショットをキャプチャします
- ネットワークアクティビティを記録します
-
トレースアクションのソースファイルを含めるかどうか。
-
トレースビューアに表示されるトレース名。
戻り値
start_chunk
v1.15で追加新しいトレースチャンクを開始します。同じBrowserContextで複数のトレースを記録する場合は、tracing.start()を1回使用し、次に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")
引数
-
指定した場合、中間トレースファイルは、browser_type.launch()で指定されたtraces_dirディレクトリ内の指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレース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()呼び出し以降に収集されたトレースを、指定されたパスを持つファイルにエクスポートします。
戻り値