Tracing
Playwrightのトレースを収集・保存するためのAPIです。Playwrightスクリプトの実行後、Playwrightのトレースはトレースビューアで開くことができます。
アクションを実行する前にトレースの記録を開始します。最後に、トレースを停止してファイルに保存します。
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
追加バージョン: v1.49利用可能な場合は、代わりに`test.step`を使用してください。
トレース内に新しいグループを作成し、tracing.groupEnd()が呼び出されるまで、以降のAPI呼び出しをこのグループに割り当てます。グループはネスト可能で、トレースビューアに表示されます。
使用方法
// use test.step instead
await test.step('Log in', async () => {
// ...
});
引数
-
トレースビューアに表示されるグループ名です。
-
options
Object (オプション)
戻り値
groupEnd
追加バージョン: v1.49tracing.group()によって作成された最後のグループを閉じます。
使用方法
await tracing.groupEnd();
戻り値
start
追加バージョン: v1.12トレースを開始します。
使用方法
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 (オプション)-
指定した場合、中間トレースファイルは、browserType.launch()で指定されたtracesDirディレクトリ内の、指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stop()に`path`オプションを渡す必要があります。
-
トレース中にスクリーンショットをキャプチャするかどうか。スクリーンショットはタイムラインプレビューを作成するために使用されます。
-
このオプションがtrueの場合、トレースは以下を行います。
- すべてのアクションでDOMスナップショットをキャプチャ
- ネットワークアクティビティを記録
-
sources
boolean (オプション)追加バージョン: v1.17#トレースアクションのソースファイルを含めるかどうか。
-
title
string (オプション)追加バージョン: v1.17#トレースビューアに表示されるトレース名です。
-
戻り値
startChunk
追加バージョン: v1.15新しいトレースチャンクを開始します。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 (オプション)-
name
string (オプション)追加バージョン: v1.32#指定した場合、中間トレースファイルは、browserType.launch()で指定されたtracesDirディレクトリ内の、指定された名前のプレフィックスを持つファイルに保存されます。最終的なトレースzipファイル名を指定するには、代わりにtracing.stopChunk()に`path`オプションを渡す必要があります。
-
title
string (オプション)追加バージョン: v1.17#トレースビューアに表示されるトレース名です。
-
戻り値
stop
追加バージョン: v1.12トレースを停止します。
使用方法
await tracing.stop();
await tracing.stop(options);
引数
戻り値
stopChunk
追加バージョン: v1.15トレースチャンクを停止します。複数のトレースチャンクの詳細については、tracing.startChunk()を参照してください。
使用方法
await tracing.stopChunk();
await tracing.stopChunk(options);
引数
options
Object (オプション)-
前回のtracing.startChunk()呼び出し以降に収集されたトレースを、指定されたパスのファイルにエクスポートします。
-
戻り値