Skip to content

Commit 5e8b469

Browse files
authored
fix(test): hide response.* calls from reports (#33620)
1 parent d7d8ab6 commit 5e8b469

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

packages/playwright-core/src/client/network.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
9797

9898
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.RequestInitializer) {
9999
super(parent, type, guid, initializer);
100+
this.markAsInternalType();
100101
this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom);
101102
if (this._redirectedFrom)
102103
this._redirectedFrom._redirectedTo = this;
@@ -645,6 +646,7 @@ export class Response extends ChannelOwner<channels.ResponseChannel> implements
645646

646647
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ResponseInitializer) {
647648
super(parent, type, guid, initializer);
649+
this.markAsInternalType();
648650
this._provisionalHeaders = new RawHeaders(initializer.headers);
649651
this._request = Request.from(this._initializer.request);
650652
Object.assign(this._request._timing, this._initializer.timing);

tests/library/trace-viewer.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,24 @@ test('should not record route actions', {
14441444
]);
14451445
});
14461446

1447+
test('should not record network actions', {
1448+
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33558' },
1449+
}, async ({ page, runAndTrace, server }) => {
1450+
const traceViewer = await runAndTrace(async () => {
1451+
page.on('request', async request => {
1452+
await request.allHeaders();
1453+
});
1454+
page.on('response', async response => {
1455+
await response.text();
1456+
});
1457+
await page.goto(server.EMPTY_PAGE);
1458+
});
1459+
1460+
await expect(traceViewer.actionTitles).toHaveText([
1461+
/page.goto.*empty.html/,
1462+
]);
1463+
});
1464+
14471465
test('should show baseURL in metadata pane', {
14481466
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31847' },
14491467
}, async ({ showTraceViewer }) => {

tests/playwright-test/test-step.spec.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,16 +1406,50 @@ pw:api |page.setContent @ a.test.ts:5
14061406
test.step |custom step @ a.test.ts:6
14071407
pw:api | page.waitForResponse @ a.test.ts:7
14081408
pw:api | page.click(div) @ a.test.ts:13
1409-
pw:api | response.text @ a.test.ts:8
14101409
expect | expect.toBeTruthy @ a.test.ts:9
1411-
pw:api | response.text @ a.test.ts:15
14121410
expect |expect.toBe @ a.test.ts:17
14131411
hook |After Hooks
14141412
fixture | fixture: page
14151413
fixture | fixture: context
14161414
`);
14171415
});
14181416

1417+
test('reading network request / response should not be listed as step', {
1418+
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33558' }
1419+
}, async ({ runInlineTest, server }) => {
1420+
const result = await runInlineTest({
1421+
'reporter.ts': stepIndentReporter,
1422+
'playwright.config.ts': `module.exports = { reporter: './reporter' };`,
1423+
'a.test.ts': `
1424+
import { test, expect } from '@playwright/test';
1425+
test('waitForResponse step nesting', async ({ page }) => {
1426+
page.on('request', async request => {
1427+
await request.allHeaders();
1428+
});
1429+
page.on('response', async response => {
1430+
await response.text();
1431+
});
1432+
await page.goto('${server.EMPTY_PAGE}');
1433+
});
1434+
`
1435+
}, { reporter: '', workers: 1, timeout: 3000 });
1436+
1437+
expect(result.exitCode).toBe(0);
1438+
expect(stripAnsi(result.output)).toBe(`
1439+
hook |Before Hooks
1440+
fixture | fixture: browser
1441+
pw:api | browserType.launch
1442+
fixture | fixture: context
1443+
pw:api | browser.newContext
1444+
fixture | fixture: page
1445+
pw:api | browserContext.newPage
1446+
pw:api |page.goto(${server.EMPTY_PAGE}) @ a.test.ts:10
1447+
hook |After Hooks
1448+
fixture | fixture: page
1449+
fixture | fixture: context
1450+
`);
1451+
});
1452+
14191453
test('calls from page.route callback should be under its parent step', {
14201454
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33186' }
14211455
}, async ({ runInlineTest, server }) => {

0 commit comments

Comments
 (0)