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

Tracing

Playwrightトレースを収集して保存するためのAPI。Playwrightスクリプトの実行後、Playwrightトレースはトレースビューアで開くことができます。

おそらくcontext.tracingを使用する代わりに、設定ファイルでトレースを有効にすることをお勧めします。

context.tracing APIはブラウザの操作とネットワークアクティビティをキャプチャしますが、テストアサーション(expect呼び出しなど)は記録しません。Playwright Testの設定を通じてトレースを有効にすることをお勧めします。これにより、これらのアサーションが含まれ、テストの失敗をデバッグするためのより完全なトレースが提供されます。

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

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');
expect(page.url()).toBe('https://playwright.dokyumento.jp');
await context.tracing.stop({ path: 'trace.zip' });

メソッド

group

追加バージョン: 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 (オプション)#

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

戻り値


groupEnd

追加バージョン: v1.49 tracing.groupEnd

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

使用法

await tracing.groupEnd();

戻り値


start

追加日: v1.12 tracing.start

トレースを開始します。

Tracing.startを使用する代わりに、設定ファイルでトレースを有効にすることをお勧めします。

context.tracing APIはブラウザの操作とネットワークアクティビティをキャプチャしますが、テストアサーション(expect呼び出しなど)は記録しません。Playwright Testの設定を通じてトレースを有効にすることをお勧めします。これにより、これらのアサーションが含まれ、テストの失敗をデバッグするためのより完全なトレースが提供されます。

使用法

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

引数

  • options Object (optional)
    • name string (オプション)#

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

    • screenshots boolean (オプション)#

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

    • snapshots boolean (オプション)#

      このオプションがtrueの場合、トレースは以下を行います。

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

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

    • title string (オプション)追加バージョン: v1.17#

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

戻り値


startChunk

追加されたバージョン: 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)追加日: v1.32#

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

    • title string (オプション)追加バージョン: v1.17#

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

戻り値


stop

追加日: v1.12 tracing.stop

トレースを停止します。

使用法

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

引数

  • options Object (optional)
    • path string (オプション)#

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

戻り値


stopChunk

追加されたバージョン: v1.15 tracing.stopChunk

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

使用法

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

引数

  • options Object (optional)
    • path string (オプション)#

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

戻り値