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

Tracing

Playwrightトレースを収集および保存するためのAPI。Playwrightトレースは、Playwrightスクリプトの実行後、Trace Viewerで開くことができます。

アクションを実行する前にトレースの記録を開始します。最後に、トレースを停止してファイルに保存します。

const browser = await chromium.launch();
const context = await browser.newContext();
await context.tracing.start({ screenshots: true, snapshots: true });
const page = await context.newPage();
await page.goto('https://playwright.dokyumento.jp');
await context.tracing.stop({ path: 'trace.zip' });

メソッド

group

Added in: v1.49 tracing.group
注意

利用可能な場合は、代わりにtest.stepを使用してください。

トレース内に新しいグループを作成し、tracing.groupEnd()が呼び出されるまで、後続のAPI呼び出しをこのグループに割り当てます。グループはネストでき、トレースビューアに表示されます。

使用法

// use test.step instead
await test.step('Log in', async () => {
// ...
});

引数

  • name string#

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

  • options Object (optional)

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

戻り値


groupEnd

Added in: v1.49 tracing.groupEnd

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

使用法

await tracing.groupEnd();

戻り値


start

Added in: v1.12 tracing.start

トレースを開始します。

使用法

await context.tracing.start({ screenshots: true, snapshots: true });
const page = await context.newPage();
await page.goto('https://playwright.dokyumento.jp');
await context.tracing.stop({ path: 'trace.zip' });

引数

  • options Object (optional)
    • name string (optional)#

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

    • screenshots boolean (optional)#

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

    • snapshots boolean (optional)#

      このオプションがtrueの場合、トレースは次のようになります

      • すべてのアクションでDOMスナップショットをキャプチャする
      • ネットワークアクティビティを記録する
    • sources boolean (optional)Added in: v1.17#

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

    • title string (optional)Added in: v1.17#

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

戻り値


startChunk

Added in: v1.15 tracing.startChunk

新しいトレースチャンクを開始します。BrowserContextで複数のトレースを記録する場合は、tracing.start()を一度使用してから、tracing.startChunk()tracing.stopChunk()を使用して複数のトレースチャンクを作成します。

使用法

await context.tracing.start({ screenshots: true, snapshots: true });
const page = await context.newPage();
await page.goto('https://playwright.dokyumento.jp');

await context.tracing.startChunk();
await page.getByText('Get Started').click();
// Everything between startChunk and stopChunk will be recorded in the trace.
await context.tracing.stopChunk({ path: 'trace1.zip' });

await context.tracing.startChunk();
await page.goto('http://example.com');
// Save a second trace file with different actions.
await context.tracing.stopChunk({ path: 'trace2.zip' });

引数

  • options Object (optional)
    • name string (optional)Added in: v1.32#

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

    • title string (optional)Added in: v1.17#

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

戻り値


stop

Added in: v1.12 tracing.stop

トレースを停止します。

使用法

await tracing.stop();
await tracing.stop(options);

引数

  • options Object (optional)
    • path string (optional)#

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

戻り値


stopChunk

Added in: v1.15 tracing.stopChunk

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

使用法

await tracing.stopChunk();
await tracing.stopChunk(options);

引数

  • options Object (optional)
    • path string (optional)#

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

戻り値