Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test): hide response.* calls from reports (#33620)

Simon Knott5e8b469c1c0b
diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts
index 74b8df9367..cb18681ccf 100644
--- a/packages/playwright-core/src/client/network.ts
+++ b/packages/playwright-core/src/client/network.ts
@@ -97,6 +97,7 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.RequestInitializer) {
super(parent, type, guid, initializer);
+ this.markAsInternalType();
this._redirectedFrom = Request.fromNullable(initializer.redirectedFrom);
if (this._redirectedFrom)
this._redirectedFrom._redirectedTo = this;
@@ -645,6 +646,7 @@ export class Response extends ChannelOwner<channels.ResponseChannel> implements
constructor(parent: ChannelOwner, type: string, guid: string, initializer: channels.ResponseInitializer) {
super(parent, type, guid, initializer);
+ this.markAsInternalType();
this._provisionalHeaders = new RawHeaders(initializer.headers);
this._request = Request.from(this._initializer.request);
Object.assign(this._request._timing, this._initializer.timing);
diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts
index 0daf06298a..7e64c62156 100644
--- a/tests/library/trace-viewer.spec.ts
+++ b/tests/library/trace-viewer.spec.ts
@@ -1444,6 +1444,24 @@ test('should not record route actions', {
]);
});
+test('should not record network actions', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33558' },
+}, async ({ page, runAndTrace, server }) => {
+ const traceViewer = await runAndTrace(async () => {
+ page.on('request', async request => {
+ await request.allHeaders();
+ });
+ page.on('response', async response => {
+ await response.text();
+ });
+ await page.goto(server.EMPTY_PAGE);
+ });
+
+ await expect(traceViewer.actionTitles).toHaveText([
+ /page.goto.*empty.html/,
+ ]);
+});
+
test('should show baseURL in metadata pane', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/31847' },
}, async ({ showTraceViewer }) => {
diff --git a/tests/playwright-test/test-step.spec.ts b/tests/playwright-test/test-step.spec.ts
index f0e3099540..ac6845eeae 100644
--- a/tests/playwright-test/test-step.spec.ts
+++ b/tests/playwright-test/test-step.spec.ts
@@ -1406,9 +1406,7 @@ pw:api |page.setContent @ a.test.ts:5
test.step |custom step @ a.test.ts:6
pw:api | page.waitForResponse @ a.test.ts:7
pw:api | page.click(div) @ a.test.ts:13
-pw:api | response.text @ a.test.ts:8
expect | expect.toBeTruthy @ a.test.ts:9
-pw:api | response.text @ a.test.ts:15
expect |expect.toBe @ a.test.ts:17
hook |After Hooks
fixture | fixture: page
@@ -1416,6 +1414,42 @@ fixture | fixture: context
`);
});
+test('reading network request / response should not be listed as step', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33558' }
+}, async ({ runInlineTest, server }) => {
+ const result = await runInlineTest({
+ 'reporter.ts': stepIndentReporter,
+ 'playwright.config.ts': `module.exports = { reporter: './reporter' };`,
+ 'a.test.ts': `
+ import { test, expect } from '@playwright/test';
+ test('waitForResponse step nesting', async ({ page }) => {
+ page.on('request', async request => {
+ await request.allHeaders();
+ });
+ page.on('response', async response => {
+ await response.text();
+ });
+ await page.goto('${server.EMPTY_PAGE}');
+ });
+ `
+ }, { reporter: '', workers: 1, timeout: 3000 });
+
+ expect(result.exitCode).toBe(0);
+ expect(stripAnsi(result.output)).toBe(`
+hook |Before Hooks
+fixture | fixture: browser
+pw:api | browserType.launch
+fixture | fixture: context
+pw:api | browser.newContext
+fixture | fixture: page
+pw:api | browserContext.newPage
+pw:api |page.goto(${server.EMPTY_PAGE}) @ a.test.ts:10
+hook |After Hooks
+fixture | fixture: page
+fixture | fixture: context
+`);
+});
+
test('calls from page.route callback should be under its parent step', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33186' }
}, async ({ runInlineTest, server }) => {