Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/playwright-core/src/client/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
}

async group(name: string, options: { location?: { file: string, line?: number, column?: number } } = {}) {
await this._channel.tracingGroup({ name, location: options.location });
await this._wrapApiCall(async zone => {
if (options.location)
zone.frames.push({ file: options.location.file, line: options.location.line ?? 0, column: options.location.column ?? 0 });
await this._channel.tracingGroup({ name, location: options.location });
});
}

async groupEnd() {
Expand Down
14 changes: 14 additions & 0 deletions tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ test('should open trace viewer on specific host', async ({ showTraceViewer }, te

test('should show tracing.group in the action list with location', async ({ runAndTrace, page, context }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36483' });
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/39302' });

const sourceFile = test.info().outputPath('source.js');
await fs.promises.writeFile(sourceFile, 'buddy beaver');

const traceViewer = await test.step('create trace with groups', async () => {
await page.context().tracing.group('ignored group');
Expand All @@ -125,15 +129,21 @@ test('should show tracing.group in the action list with location', async ({ runA
await context.tracing.group('inner group 2');
await expect(page.getByText('Hello')).toBeVisible();
await context.tracing.groupEnd();
await context.tracing.group('inner group 3', { location: { file: sourceFile, line: 1, column: 1 } });
await expect(page.getByText('Hello')).toBeVisible();
await context.tracing.groupEnd();
await context.tracing.groupEnd();
});
});

await fs.promises.rm(sourceFile);

await expect(traceViewer.actionTitles).toHaveText([
/outer group/,
/Navigate/,
/inner group 1 {{ eager_beaver }}/,
/inner group 2/,
/inner group 3/,
/toBeVisible/,
]);

Expand All @@ -145,12 +155,16 @@ test('should show tracing.group in the action list with location', async ({ runA
/inner group 1 {{ eager_beaver }}/,
/Click.*locator/,
/inner group 2/,
/inner group 3/,
]);
await traceViewer.showSourceTab();
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toHaveText(/DO NOT TOUCH THIS LINE/);

await traceViewer.selectAction('inner group 2');
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toContainText("await context.tracing.group('inner group 2');");

await traceViewer.selectAction('inner group 3');
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toContainText('buddy beaver');
});

test('should open simple trace viewer', async ({ showTraceViewer }) => {
Expand Down
Loading