docs(tracing): clarify diff between test tracing and context.tracing (#35852)

This commit is contained in:
Adam Gastineau 2025-05-06 11:25:33 -07:00 committed by GitHub
parent 8e08fdb52c
commit 00429efc4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 0 deletions

View File

@ -3,6 +3,12 @@
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](../trace-viewer.md) after Playwright script runs.
:::note
You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `context.tracing`.
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
:::
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
```js
@ -11,6 +17,7 @@ const context = await browser.newContext();
await context.tracing.start({ screenshots: true, snapshots: true });
const page = await context.newPage();
await page.goto('https://playwright.dev');
expect(page.url()).toBe('https://playwright.dev');
await context.tracing.stop({ path: 'trace.zip' });
```
@ -66,12 +73,19 @@ await context.Tracing.StopAsync(new()
Start tracing.
:::note
You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `Tracing.start`.
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
:::
**Usage**
```js
await context.tracing.start({ screenshots: true, snapshots: true });
const page = await context.newPage();
await page.goto('https://playwright.dev');
expect(page.url()).toBe('https://playwright.dev');
await context.tracing.stop({ path: 'trace.zip' });
```

View File

@ -21175,6 +21175,15 @@ export interface Touchscreen {
* API for collecting and saving Playwright traces. Playwright traces can be opened in
* [Trace Viewer](https://playwright.dev/docs/trace-viewer) after Playwright script runs.
*
* **NOTE** You probably want to
* [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead
* of using `context.tracing`.
*
* The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions
* (like `expect` calls). We recommend
* [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace),
* which includes those assertions and provides a more complete trace for debugging test failures.
*
* Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
*
* ```js
@ -21183,6 +21192,7 @@ export interface Touchscreen {
* await context.tracing.start({ screenshots: true, snapshots: true });
* const page = await context.newPage();
* await page.goto('https://playwright.dev');
* expect(page.url()).toBe('https://playwright.dev');
* await context.tracing.stop({ path: 'trace.zip' });
* ```
*
@ -21230,12 +21240,22 @@ export interface Tracing {
/**
* Start tracing.
*
* **NOTE** You probably want to
* [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead
* of using `Tracing.start`.
*
* The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions
* (like `expect` calls). We recommend
* [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace),
* which includes those assertions and provides a more complete trace for debugging test failures.
*
* **Usage**
*
* ```js
* await context.tracing.start({ screenshots: true, snapshots: true });
* const page = await context.newPage();
* await page.goto('https://playwright.dev');
* expect(page.url()).toBe('https://playwright.dev');
* await context.tracing.stop({ path: 'trace.zip' });
* ```
*

View File

@ -21175,6 +21175,15 @@ export interface Touchscreen {
* API for collecting and saving Playwright traces. Playwright traces can be opened in
* [Trace Viewer](https://playwright.dev/docs/trace-viewer) after Playwright script runs.
*
* **NOTE** You probably want to
* [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead
* of using `context.tracing`.
*
* The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions
* (like `expect` calls). We recommend
* [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace),
* which includes those assertions and provides a more complete trace for debugging test failures.
*
* Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
*
* ```js
@ -21183,6 +21192,7 @@ export interface Touchscreen {
* await context.tracing.start({ screenshots: true, snapshots: true });
* const page = await context.newPage();
* await page.goto('https://playwright.dev');
* expect(page.url()).toBe('https://playwright.dev');
* await context.tracing.stop({ path: 'trace.zip' });
* ```
*
@ -21230,12 +21240,22 @@ export interface Tracing {
/**
* Start tracing.
*
* **NOTE** You probably want to
* [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead
* of using `Tracing.start`.
*
* The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions
* (like `expect` calls). We recommend
* [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace),
* which includes those assertions and provides a more complete trace for debugging test failures.
*
* **Usage**
*
* ```js
* await context.tracing.start({ screenshots: true, snapshots: true });
* const page = await context.newPage();
* await page.goto('https://playwright.dev');
* expect(page.url()).toBe('https://playwright.dev');
* await context.tracing.stop({ path: 'trace.zip' });
* ```
*