Skip to content

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

chore: recover from exceptions in matcher queries (#37215)

Pavel Feldman341611871ac1
diff --git a/packages/playwright/src/matchers/toBeTruthy.ts b/packages/playwright/src/matchers/toBeTruthy.ts
index 6f627c994c..7e3f1dbcaf 100644
--- a/packages/playwright/src/matchers/toBeTruthy.ts
+++ b/packages/playwright/src/matchers/toBeTruthy.ts
@@ -40,7 +40,13 @@ export async function toBeTruthy(
};
const timeout = options.timeout ?? this.timeout;
- const { matches: pass, log, timedOut, received } = await query(!!this.isNot, timeout);
+
+ const { matches: pass, log, timedOut, received } = await query(!!this.isNot, timeout).catch(async error => {
+ // FIXME: query should not throw, but it does for strict mode violations for example.
+ await runBrowserBackendOnError(receiver.page(), () => error.message);
+ throw error;
+ });
+
if (pass === !this.isNot) {
return {
name: matcherName,
diff --git a/packages/playwright/src/matchers/toEqual.ts b/packages/playwright/src/matchers/toEqual.ts
index c188de257b..410049b23a 100644
--- a/packages/playwright/src/matchers/toEqual.ts
+++ b/packages/playwright/src/matchers/toEqual.ts
@@ -48,7 +48,12 @@ export async function toEqual<T>(
const timeout = options.timeout ?? this.timeout;
- const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout);
+ const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout).catch(async error => {
+ // FIXME: query should not throw, but it does for strict mode violations for example.
+ await runBrowserBackendOnError(receiver.page(), () => error.message);
+ throw error;
+ });
+
if (pass === !this.isNot) {
return {
name: matcherName,
diff --git a/packages/playwright/src/matchers/toMatchText.ts b/packages/playwright/src/matchers/toMatchText.ts
index 712f8361a8..65630e2ffc 100644
--- a/packages/playwright/src/matchers/toMatchText.ts
+++ b/packages/playwright/src/matchers/toMatchText.ts
@@ -60,7 +60,13 @@ export async function toMatchText(
const timeout = options.timeout ?? this.timeout;
- const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout);
+ const { matches: pass, received, log, timedOut } = await query(!!this.isNot, timeout).catch(async error => {
+ // FIXME: query should not throw, but it does for strict mode violations for example.
+ if (receiverType === 'Locator')
+ await runBrowserBackendOnError((receiver as Locator).page(), () => error.message);
+ throw error;
+ });
+
if (pass === !this.isNot) {
return {
name: matcherName,