Skip to content

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

fix: restore timeout error name (#28408)

Pavel Feldman92a0d24069c2
diff --git a/packages/playwright-core/src/client/errors.ts b/packages/playwright-core/src/client/errors.ts
index 06446ba3b6..4d8a08c4ac 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 1dd83daca4..16b3210caa 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 d98b580c2e..fa303bf7b8 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\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<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\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<snippet>\"}}`,
`begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`,
`begin {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,
`end {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,