diff --git a/packages/playwright-core/src/client/consoleMessage.ts b/packages/playwright-core/src/client/consoleMessage.ts index 9c6d5afeb2..58caf3e97c 100644 --- a/packages/playwright-core/src/client/consoleMessage.ts +++ b/packages/playwright-core/src/client/consoleMessage.ts @@ -47,7 +47,7 @@ export class ConsoleMessage extends ChannelOwner ` ${name}: ${value}`); + return `APIResponse: ${this.status()} ${this.statusText()}\n${headers.join('\n')}`; + } + _fetchUid(): string { return this._initializer.fetchUid; } diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts index 706d4381a8..8c0fdb6b86 100644 --- a/packages/playwright-core/src/client/locator.ts +++ b/packages/playwright-core/src/client/locator.ts @@ -241,7 +241,7 @@ export class Locator implements api.Locator { }); } - [(util.inspect as any).custom]() { + [util.inspect.custom]() { return this.toString(); } diff --git a/tests/global-fetch.spec.ts b/tests/global-fetch.spec.ts index 002969fd77..1aa36e4383 100644 --- a/tests/global-fetch.spec.ts +++ b/tests/global-fetch.spec.ts @@ -15,6 +15,7 @@ */ import http from 'http'; +import * as util from 'util'; import { getPlaywrightVersion } from 'playwright-core/lib/utils/utils'; import { expect, playwrightTest as it } from './config/browserTest'; @@ -294,3 +295,18 @@ it(`should accept already serialized data as Buffer when content-type is applica expect(body.toString()).toEqual(value); await request.dispose(); }); + +it(`should have nice toString`, async ({ playwright, server }) => { + const request = await playwright.request.newContext(); + const response = await request.post(server.EMPTY_PAGE, { + headers: { + 'content-type': 'application/json' + }, + data: 'My post data' + }); + const str = response[util.inspect.custom](); + expect(str).toContain('APIResponse: 200 OK'); + for (const { name, value } of response.headersArray()) + expect(str).toContain(` ${name}: ${value}`); + await request.dispose(); +});