mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
api(tracing): export -> stop({path}) (#6802)
This commit is contained in:
parent
79b244a2f4
commit
d28f45b6ee
@ -12,8 +12,7 @@ const context = await browser.newContext();
|
|||||||
await context.tracing.start({ name: 'trace', screenshots: true, snapshots: true });
|
await context.tracing.start({ name: 'trace', screenshots: true, snapshots: true });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
await page.goto('https://playwright.dev');
|
await page.goto('https://playwright.dev');
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: 'trace.zip' });
|
||||||
await context.tracing.export('trace.zip');
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@ -25,8 +24,8 @@ context.tracing.start(page, new Tracing.StartOptions()
|
|||||||
.setSnapshots(true);
|
.setSnapshots(true);
|
||||||
Page page = context.newPage();
|
Page page = context.newPage();
|
||||||
page.goto("https://playwright.dev");
|
page.goto("https://playwright.dev");
|
||||||
context.tracing.stop();
|
context.tracing.stop(new Tracing.StopOptions()
|
||||||
context.tracing.export(Paths.get("trace.zip")))
|
.setSaveAs(Paths.get("trace.zip")));
|
||||||
```
|
```
|
||||||
|
|
||||||
```python async
|
```python async
|
||||||
@ -34,8 +33,7 @@ browser = await chromium.launch(traceDir='traces')
|
|||||||
context = await browser.new_context()
|
context = await browser.new_context()
|
||||||
await context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
await context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
||||||
await page.goto("https://playwright.dev")
|
await page.goto("https://playwright.dev")
|
||||||
await context.tracing.stop()
|
await context.tracing.stop(save_as = "trace.zip")
|
||||||
await context.tracing.export("trace.zip")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python sync
|
```python sync
|
||||||
@ -43,20 +41,9 @@ browser = chromium.launch(traceDir='traces')
|
|||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
context.tracing.start(name="trace", screenshots=True, snapshots=True)
|
||||||
page.goto("https://playwright.dev")
|
page.goto("https://playwright.dev")
|
||||||
context.tracing.stop()
|
context.tracing.stop(save_as = "trace.zip")
|
||||||
context.tracing.export("trace.zip")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## async method: Tracing.export
|
|
||||||
|
|
||||||
Export trace into the file with the given name. Should be called after the
|
|
||||||
tracing has stopped.
|
|
||||||
|
|
||||||
### param: Tracing.export.path
|
|
||||||
- `path` <[path]>
|
|
||||||
|
|
||||||
File to save the trace into.
|
|
||||||
|
|
||||||
## async method: Tracing.start
|
## async method: Tracing.start
|
||||||
|
|
||||||
Start tracing.
|
Start tracing.
|
||||||
@ -114,3 +101,8 @@ Whether to capture DOM snapshot on every action.
|
|||||||
## async method: Tracing.stop
|
## async method: Tracing.stop
|
||||||
|
|
||||||
Stop tracing.
|
Stop tracing.
|
||||||
|
|
||||||
|
### option: Tracing.stop.path
|
||||||
|
- `path` <[path]>
|
||||||
|
|
||||||
|
Export trace into the file with the given name.
|
||||||
|
@ -32,20 +32,17 @@ export class Tracing implements api.Tracing {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async stop() {
|
async stop(options: { path?: string } = {}) {
|
||||||
await this._context._wrapApiCall('tracing.stop', async (channel: channels.BrowserContextChannel) => {
|
await this._context._wrapApiCall('tracing.stop', async (channel: channels.BrowserContextChannel) => {
|
||||||
await channel.tracingStop();
|
await channel.tracingStop();
|
||||||
});
|
if (options.path) {
|
||||||
}
|
const result = await channel.tracingExport();
|
||||||
|
|
||||||
async export(path: string): Promise<void> {
|
|
||||||
const result = await this._context._wrapApiCall('tracing.export', async (channel: channels.BrowserContextChannel) => {
|
|
||||||
return await channel.tracingExport();
|
|
||||||
});
|
|
||||||
const artifact = Artifact.from(result.artifact);
|
const artifact = Artifact.from(result.artifact);
|
||||||
if (this._context.browser()?._remoteType)
|
if (this._context.browser()?._remoteType)
|
||||||
artifact._isRemote = true;
|
artifact._isRemote = true;
|
||||||
await artifact.saveAs(path);
|
await artifact.saveAs(options.path);
|
||||||
await artifact.delete();
|
await artifact.delete();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,7 @@ test('should collect trace', async ({ context, page, server, browserName }, test
|
|||||||
await page.setContent('<button>Click</button>');
|
await page.setContent('<button>Click</button>');
|
||||||
await page.click('"Click"');
|
await page.click('"Click"');
|
||||||
await page.close();
|
await page.close();
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace.zip'));
|
|
||||||
|
|
||||||
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
||||||
expect(events[0].type).toBe('context-options');
|
expect(events[0].type).toBe('context-options');
|
||||||
@ -50,13 +49,12 @@ test('should collect trace', async ({ context, page, server, browserName }, test
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should collect trace', async ({ context, page, server }, testInfo) => {
|
test('should collect trace', async ({ context, page, server }, testInfo) => {
|
||||||
await context.tracing.start({ name: 'test' });
|
await context.tracing.start();
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await page.setContent('<button>Click</button>');
|
await page.setContent('<button>Click</button>');
|
||||||
await page.click('"Click"');
|
await page.click('"Click"');
|
||||||
await page.close();
|
await page.close();
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace.zip'));
|
|
||||||
|
|
||||||
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
const { events } = await parseTrace(testInfo.outputPath('trace.zip'));
|
||||||
expect(events.some(e => e.type === 'frame-snapshot')).toBeFalsy();
|
expect(events.some(e => e.type === 'frame-snapshot')).toBeFalsy();
|
||||||
@ -67,11 +65,10 @@ test('should exclude internal pages', async ({ browserName, context, page, serve
|
|||||||
test.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');
|
test.fixme(true, 'https://github.com/microsoft/playwright/issues/6743');
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
|
||||||
await context.tracing.start({ name: 'test' });
|
await context.tracing.start();
|
||||||
await context.storageState();
|
await context.storageState();
|
||||||
await page.close();
|
await page.close();
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace.zip'));
|
|
||||||
|
|
||||||
const trace = await parseTrace(testInfo.outputPath('trace.zip'));
|
const trace = await parseTrace(testInfo.outputPath('trace.zip'));
|
||||||
const pageIds = new Set();
|
const pageIds = new Set();
|
||||||
@ -84,18 +81,16 @@ test('should exclude internal pages', async ({ browserName, context, page, serve
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should collect two traces', async ({ context, page, server }, testInfo) => {
|
test('should collect two traces', async ({ context, page, server }, testInfo) => {
|
||||||
await context.tracing.start({ name: 'test1', screenshots: true, snapshots: true });
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
await page.setContent('<button>Click</button>');
|
await page.setContent('<button>Click</button>');
|
||||||
await page.click('"Click"');
|
await page.click('"Click"');
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace1.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace1.zip'));
|
|
||||||
|
|
||||||
await context.tracing.start({ name: 'test2', screenshots: true, snapshots: true });
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
await page.dblclick('"Click"');
|
await page.dblclick('"Click"');
|
||||||
await page.close();
|
await page.close();
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace2.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace2.zip'));
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const { events } = await parseTrace(testInfo.outputPath('trace1.zip'));
|
const { events } = await parseTrace(testInfo.outputPath('trace1.zip'));
|
||||||
@ -145,15 +140,14 @@ for (const params of [
|
|||||||
const previewHeight = params.height * scale;
|
const previewHeight = params.height * scale;
|
||||||
|
|
||||||
const context = await contextFactory({ viewport: { width: params.width, height: params.height }});
|
const context = await contextFactory({ viewport: { width: params.width, height: params.height }});
|
||||||
await context.tracing.start({ name: 'test', screenshots: true, snapshots: true });
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
// Make sure we have a chance to paint.
|
// Make sure we have a chance to paint.
|
||||||
for (let i = 0; i < 10; ++i) {
|
for (let i = 0; i < 10; ++i) {
|
||||||
await page.setContent('<body style="box-sizing: border-box; width: 100%; height: 100%; margin:0; background: red; border: 50px solid blue"></body>');
|
await page.setContent('<body style="box-sizing: border-box; width: 100%; height: 100%; margin:0; background: red; border: 50px solid blue"></body>');
|
||||||
await page.evaluate(() => new Promise(requestAnimationFrame));
|
await page.evaluate(() => new Promise(requestAnimationFrame));
|
||||||
}
|
}
|
||||||
await context.tracing.stop();
|
await context.tracing.stop({ path: testInfo.outputPath('trace.zip') });
|
||||||
await context.tracing.export(testInfo.outputPath('trace.zip'));
|
|
||||||
|
|
||||||
const { events, resources } = await parseTrace(testInfo.outputPath('trace.zip'));
|
const { events, resources } = await parseTrace(testInfo.outputPath('trace.zip'));
|
||||||
const frames = events.filter(e => e.type === 'screencast-frame');
|
const frames = events.filter(e => e.type === 'screencast-frame');
|
||||||
|
17
types/types.d.ts
vendored
17
types/types.d.ts
vendored
@ -10609,18 +10609,11 @@ export interface Touchscreen {
|
|||||||
* await context.tracing.start({ name: 'trace', screenshots: true, snapshots: true });
|
* await context.tracing.start({ name: 'trace', screenshots: true, snapshots: true });
|
||||||
* const page = await context.newPage();
|
* const page = await context.newPage();
|
||||||
* await page.goto('https://playwright.dev');
|
* await page.goto('https://playwright.dev');
|
||||||
* await context.tracing.stop();
|
* await context.tracing.stop({ path: 'trace.zip' });
|
||||||
* await context.tracing.export('trace.zip');
|
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export interface Tracing {
|
export interface Tracing {
|
||||||
/**
|
|
||||||
* Export trace into the file with the given name. Should be called after the tracing has stopped.
|
|
||||||
* @param path File to save the trace into.
|
|
||||||
*/
|
|
||||||
export(path: string): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start tracing.
|
* Start tracing.
|
||||||
*
|
*
|
||||||
@ -10654,8 +10647,14 @@ export interface Tracing {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop tracing.
|
* Stop tracing.
|
||||||
|
* @param options
|
||||||
*/
|
*/
|
||||||
stop(): Promise<void>;
|
stop(options?: {
|
||||||
|
/**
|
||||||
|
* Export trace into the file with the given name.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
}): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user