From 92a0d24069c2f43ecec89ac9528ff47577273b9d Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 29 Nov 2023 17:28:17 -0800 Subject: [PATCH] fix: restore timeout error name (#28408) Fixes https://github.com/microsoft/playwright/issues/28404 --- packages/playwright-core/src/client/errors.ts | 8 +++++++- tests/page/expect-timeout.spec.ts | 5 +++++ tests/playwright-test/reporter.spec.ts | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/client/errors.ts b/packages/playwright-core/src/client/errors.ts index 06446ba3b6231..4d8a08c4ac65b 100644 --- a/packages/playwright-core/src/client/errors.ts +++ b/packages/playwright-core/src/client/errors.ts @@ -18,11 +18,17 @@ import type { SerializedError } from '@protocol/channels'; import { isError } from '../utils'; import { parseSerializedValue, serializeValue } from '../protocol/serializers'; -export class TimeoutError extends Error {} +export class TimeoutError extends Error { + constructor(message: string) { + super(message); + this.name = 'TimeoutError'; + } +} export class TargetClosedError extends Error { constructor(cause?: string) { super(cause || 'Target page, context or browser has been closed'); + this.name = 'TargetClosedError'; } } diff --git a/tests/page/expect-timeout.spec.ts b/tests/page/expect-timeout.spec.ts index 1dd83daca4f56..16b3210caa72a 100644 --- a/tests/page/expect-timeout.spec.ts +++ b/tests/page/expect-timeout.spec.ts @@ -50,3 +50,8 @@ test('should not print timed out error message when page closes', async ({ page expect(stripAnsi(error.message)).toContain('expect.toHaveText with timeout 100000ms'); expect(stripAnsi(error.message)).not.toContain('Timed out'); }); + +test('should have timeout error name', async ({ page }) => { + const error = await page.waitForSelector('#not-found', { timeout: 1 }).catch(e => e); + expect(error.name).toBe('TimeoutError'); +}); diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.ts index d98b580c2ee3d..fa303bf7b8355 100644 --- a/tests/playwright-test/reporter.spec.ts +++ b/tests/playwright-test/reporter.spec.ts @@ -454,7 +454,7 @@ for (const useIntermediateMergeReport of [false, true] as const) { `begin {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`, `end {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`, `begin {\"title\":\"page.click(input)\",\"category\":\"pw:api\"}`, - `end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"Error: page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"\",\"location\":\"\",\"snippet\":\"\"}}`, + `end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"TimeoutError: page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"\",\"location\":\"\",\"snippet\":\"\"}}`, `begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`, `begin {\"title\":\"fixture: page\",\"category\":\"fixture\"}`, `end {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,