2021-05-12 12:21:54 -07:00
|
|
|
# class: Tracing
|
2021-05-13 12:24:20 -07:00
|
|
|
* langs: js, python, java
|
2021-05-12 12:21:54 -07:00
|
|
|
|
2021-05-13 11:22:12 -07:00
|
|
|
API for collecting and saving Playwright traces. Playwright traces can be opened using the Playwright CLI after
|
2021-05-12 16:16:36 -07:00
|
|
|
Playwright script runs.
|
|
|
|
|
|
|
|
Start with specifying the folder traces will be stored in:
|
|
|
|
|
|
|
|
```js
|
2021-06-02 22:00:34 -07:00
|
|
|
const browser = await chromium.launch();
|
2021-05-12 16:16:36 -07:00
|
|
|
const context = await browser.newContext();
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-05-12 16:16:36 -07:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto('https://playwright.dev');
|
2021-06-02 10:04:25 -07:00
|
|
|
await context.tracing.stop({ path: 'trace.zip' });
|
2021-05-12 16:16:36 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
2021-06-02 22:00:34 -07:00
|
|
|
Browser browser = chromium.launch();
|
2021-05-12 16:16:36 -07:00
|
|
|
BrowserContext context = browser.newContext();
|
|
|
|
context.tracing.start(page, new Tracing.StartOptions()
|
|
|
|
.setScreenshots(true)
|
|
|
|
.setSnapshots(true);
|
|
|
|
Page page = context.newPage();
|
|
|
|
page.goto("https://playwright.dev");
|
2021-06-02 10:04:25 -07:00
|
|
|
context.tracing.stop(new Tracing.StopOptions()
|
2021-06-02 22:00:34 -07:00
|
|
|
.setPath(Paths.get("trace.zip")));
|
2021-05-12 16:16:36 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
2021-06-02 22:00:34 -07:00
|
|
|
browser = await chromium.launch()
|
2021-05-12 16:16:36 -07:00
|
|
|
context = await browser.new_context()
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.start(screenshots=True, snapshots=True)
|
2021-05-12 16:16:36 -07:00
|
|
|
await page.goto("https://playwright.dev")
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.stop(path = "trace.zip")
|
2021-05-12 16:16:36 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
2021-06-02 22:00:34 -07:00
|
|
|
browser = chromium.launch()
|
2021-05-12 16:16:36 -07:00
|
|
|
context = browser.new_context()
|
2021-06-02 22:00:34 -07:00
|
|
|
context.tracing.start(screenshots=True, snapshots=True)
|
2021-05-12 16:16:36 -07:00
|
|
|
page.goto("https://playwright.dev")
|
2021-06-02 22:00:34 -07:00
|
|
|
context.tracing.stop(path = "trace.zip")
|
2021-05-12 16:16:36 -07:00
|
|
|
```
|
2021-05-12 12:21:54 -07:00
|
|
|
|
|
|
|
## async method: Tracing.start
|
|
|
|
|
|
|
|
Start tracing.
|
|
|
|
|
|
|
|
```js
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
2021-05-12 12:21:54 -07:00
|
|
|
const page = await context.newPage();
|
|
|
|
await page.goto('https://playwright.dev');
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.stop({ path: 'trace.zip' });
|
2021-05-12 12:21:54 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```java
|
|
|
|
context.tracing.start(page, new Tracing.StartOptions()
|
|
|
|
.setScreenshots(true)
|
|
|
|
.setSnapshots(true);
|
|
|
|
Page page = context.newPage();
|
|
|
|
page.goto('https://playwright.dev');
|
2021-06-02 22:00:34 -07:00
|
|
|
context.tracing.stop(new Tracing.StopOptions()
|
|
|
|
.setPath(Paths.get("trace.zip")));
|
2021-05-12 12:21:54 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```python async
|
2021-05-12 16:16:36 -07:00
|
|
|
await context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
2021-05-12 12:21:54 -07:00
|
|
|
await page.goto("https://playwright.dev")
|
|
|
|
await context.tracing.stop()
|
2021-06-02 22:00:34 -07:00
|
|
|
await context.tracing.stop(path = "trace.zip")
|
2021-05-12 12:21:54 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
2021-05-12 16:16:36 -07:00
|
|
|
context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
2021-05-12 12:21:54 -07:00
|
|
|
page.goto("https://playwright.dev")
|
|
|
|
context.tracing.stop()
|
2021-06-02 22:00:34 -07:00
|
|
|
context.tracing.stop(path = "trace.zip")
|
2021-05-12 12:21:54 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
### option: Tracing.start.name
|
|
|
|
- `name` <[string]>
|
|
|
|
|
|
|
|
If specified, the trace is going to be saved into the file with the
|
2021-06-02 22:00:34 -07:00
|
|
|
given name inside the [`option: tracesDir`] folder specified in [`method: BrowserType.launch`].
|
2021-05-12 12:21:54 -07:00
|
|
|
|
|
|
|
### option: Tracing.start.screenshots
|
|
|
|
- `screenshots` <[boolean]>
|
|
|
|
|
|
|
|
Whether to capture screenshots during tracing. Screenshots are used to build
|
|
|
|
a timeline preview.
|
|
|
|
|
|
|
|
### option: Tracing.start.snapshots
|
|
|
|
- `snapshots` <[boolean]>
|
|
|
|
|
|
|
|
Whether to capture DOM snapshot on every action.
|
|
|
|
|
|
|
|
## async method: Tracing.stop
|
|
|
|
|
|
|
|
Stop tracing.
|
2021-06-02 10:04:25 -07:00
|
|
|
|
|
|
|
### option: Tracing.stop.path
|
|
|
|
- `path` <[path]>
|
|
|
|
|
|
|
|
Export trace into the file with the given name.
|