メインコンテンツにスキップ

トレーシング

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

メソッド

group

v1.49で追加 tracing.group
注意

可能な場合は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()

引数

  • name str#

    トレースビューアに表示されるグループ名。

  • location Dict (オプション)#

    • file str

    • line int (オプション)

    • column int (オプション)

    トレースビューアに表示するグループのカスタムロケーションを指定します。デフォルトは、tracing.group()呼び出しのロケーションです。

戻り値


group_end

v1.49で追加 tracing.group_end

tracing.group()によって作成された最後のグループを閉じます。

使用法

tracing.group_end()

戻り値


start

v1.12で追加 tracing.start

トレースを開始します。

使用法

context.tracing.start(screenshots=True, snapshots=True)
page = context.new_page()
page.goto("https://playwright.dokyumento.jp")
context.tracing.stop(path = "trace.zip")

引数

  • name str (オプション)#

    指定した場合、中間トレースファイルは、browser_type.launch()で指定されたtraces_dirディレクトリ内の指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stop()pathオプションを渡す必要があります。

  • screenshots bool (オプション)#

    トレース中にスクリーンショットをキャプチャするかどうか。スクリーンショットは、タイムラインプレビューを構築するために使用されます。

  • snapshots bool (オプション)#

    このオプションがtrueの場合、トレースは

    • すべてのアクションでDOMスナップショットをキャプチャします
    • ネットワークアクティビティを記録します
  • sources bool (オプション)v1.17で追加#

    トレースアクションのソースファイルを含めるかどうか。

  • title str (オプション)v1.17で追加#

    トレースビューアに表示されるトレース名。

戻り値


start_chunk

v1.15で追加 tracing.start_chunk

新しいトレースチャンクを開始します。同じ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")

引数

  • name str (オプション)v1.32で追加#

    指定した場合、中間トレースファイルは、browser_type.launch()で指定されたtraces_dirディレクトリ内の指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stop_chunk()pathオプションを渡す必要があります。

  • title str (オプション)v1.17で追加#

    トレースビューアに表示されるトレース名。

戻り値


stop

v1.12で追加 tracing.stop

トレースを停止します。

使用法

tracing.stop()
tracing.stop(**kwargs)

引数

  • path Union[str, pathlib.Path] (オプション)#

    指定されたパスを持つファイルにトレースをエクスポートします。

戻り値


stop_chunk

v1.15で追加 tracing.stop_chunk

トレースチャンクを停止します。tracing.start_chunk()で、複数のトレースチャンクの詳細を参照してください。

使用法

tracing.stop_chunk()
tracing.stop_chunk(**kwargs)

引数

  • path Union[str, pathlib.Path] (オプション)#

    最後のtracing.start_chunk()呼び出し以降に収集されたトレースを、指定されたパスを持つファイルにエクスポートします。

戻り値