Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(expect): explicit errorMessage (#37253)
Dmitry Gozman18afd41ece97
diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.tsindex 7aaa8353f1..9470ebc712 100644--- a/packages/playwright-core/src/client/frame.ts+++ b/packages/playwright-core/src/client/frame.ts@@ -466,7 +466,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Frreturn (await this._channel.title()).value;}- async _expect(expression: string, options: Omit<channels.FrameExpectParams, 'expression'>): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {+ async _expect(expression: string, options: Omit<channels.FrameExpectParams, 'expression'>): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string }> {const params: channels.FrameExpectParams = { expression, ...options, isNot: !!options.isNot };params.expectedValue = serializeArgument(options.expectedValue);const result = (await this._channel.expect(params));diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.tsindex f7afdbb5fe..fd889c75f3 100644--- a/packages/playwright-core/src/client/locator.ts+++ b/packages/playwright-core/src/client/locator.ts@@ -377,7 +377,7 @@ export class Locator implements api.Locator {await this._frame._channel.waitForSelector({ selector: this._selector, strict: true, omitReturnValue: true, ...options, timeout: this._frame._timeout(options) });}- async _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {+ async _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string }> {return this._frame._expect(expression, {...options,selector: this._selector,diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.tsindex f290f49e2d..27c6d635eb 100644--- a/packages/playwright-core/src/protocol/validator.ts+++ b/packages/playwright-core/src/protocol/validator.ts@@ -1922,6 +1922,7 @@ scheme.FrameExpectResult = tObject({matches: tBoolean,received: tOptional(tType('SerializedValue')),timedOut: tOptional(tBoolean),+ errorMessage: tOptional(tString),log: tOptional(tArray(tString)),});scheme.WorkerInitializer = tObject({diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.tsindex 891de22817..4fd2e7368b 100644--- a/packages/playwright-core/src/server/frames.ts+++ b/packages/playwright-core/src/server/frames.ts@@ -90,7 +90,7 @@ export class NavigationAbortedError extends Error {}}-type ExpectResult = { matches: boolean, received?: any, log?: string[], timedOut?: boolean };+type ExpectResult = { matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string };const kDummyFrameId = '<dummy>';@@ -1356,7 +1356,7 @@ export class Frame extends SdkObject {async expect(progress: Progress, selector: string | undefined, options: FrameExpectParams, timeout?: number): Promise<ExpectResult> {progress.log(`${renderTitleForCall(progress.metadata)}${timeout ? ` with timeout ${timeout}ms` : ''}`);- const lastIntermediateResult: { received?: any, isSet: boolean } = { isSet: false };+ const lastIntermediateResult: { received?: any, isSet: boolean, errorMessage?: string } = { isSet: false };const fixupMetadataError = (result: ExpectResult) => {// Library mode special case for the expect errors which are return values, not exceptions.if (result.matches === options.isNot)@@ -1398,11 +1398,15 @@ export class Frame extends SdkObject {} catch (e) {// Q: Why not throw upon isNonRetriableError(e) as in other places?// A: We want user to receive a friendly message containing the last intermediate result.- if (js.isJavaScriptErrorInEvaluate(e) || isInvalidSelectorError(e))- throw e;const result: ExpectResult = { matches: options.isNot, log: compressCallLog(progress.metadata.log) };- if (lastIntermediateResult.isSet)+ if (isInvalidSelectorError(e)) {+ result.errorMessage = 'Error: ' + e.message;+ } else if (js.isJavaScriptErrorInEvaluate(e)) {+ result.errorMessage = e.message;+ } else if (lastIntermediateResult.isSet) {result.received = lastIntermediateResult.received;+ result.errorMessage = lastIntermediateResult.errorMessage;+ }if (e instanceof TimeoutError)result.timedOut = true;fixupMetadataError(result);@@ -1410,7 +1414,7 @@ export class Frame extends SdkObject {}}- private async _expectInternal(progress: Progress, selector: string | undefined, options: FrameExpectParams, lastIntermediateResult: { received?: any, isSet: boolean }, noAbort: boolean) {+ private async _expectInternal(progress: Progress, selector: string | undefined, options: FrameExpectParams, lastIntermediateResult: { received?: any, isSet: boolean, errorMessage?: string }, noAbort: boolean) {// The first expect check, a.k.a. one-shot, always finishes - even when progress is aborted.const race = <T>(p: Promise<T>) => noAbort ? p : progress.race(p);const selectorInFrame = selector ? await race(this.selectors.resolveFrameForSelector(selector, { strict: true })) : undefined;@@ -1439,7 +1443,10 @@ export class Frame extends SdkObject {progress.log(log);// Note: missingReceived avoids `unexpected value "undefined"` when element was not found.if (matches === options.isNot) {- lastIntermediateResult.received = missingReceived ? '<element(s) not found>' : received;+ if (missingReceived)+ lastIntermediateResult.errorMessage = 'Error: element(s) not found';+ else+ lastIntermediateResult.received = received;lastIntermediateResult.isSet = true;if (!missingReceived && !Array.isArray(received))progress.log(` unexpected value "${renderUnexpectedValue(options.expression, received)}"`);diff --git a/packages/playwright/src/matchers/matcherHint.ts b/packages/playwright/src/matchers/matcherHint.tsindex 0505f0676c..65328ed68d 100644--- a/packages/playwright/src/matchers/matcherHint.ts+++ b/packages/playwright/src/matchers/matcherHint.ts@@ -20,8 +20,6 @@ import type { ExpectMatcherState } from '../../types/test';import type { StackFrame } from '@protocol/channels';import type { Locator } from 'playwright-core';-export const kNoElementsFoundError = '<element(s) not found>';-export function matcherHint(state: ExpectMatcherState, locator: Locator | undefined, matcherName: string, expression: any, actual: any, matcherOptions: any, timeout: number | undefined, expectedReceivedString?: string, preventExtraStatIndent: boolean = false) {let header = state.utils.matcherHint(matcherName, expression, actual, matcherOptions).replace(/ \/\/ deep equality/, '') + ' failed\n\n';// Extra space added after locator and timeout to match Jest's received/expected outputdiff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.tsindex bc4e3a7f3e..78db00e9c5 100644--- a/packages/playwright/src/matchers/matchers.ts+++ b/packages/playwright/src/matchers/matchers.ts@@ -34,11 +34,11 @@ import type { FrameExpectParams } from 'playwright-core/lib/client/types';export type ExpectMatcherStateInternal = ExpectMatcherState & { _stepInfo?: TestStepInfoImpl };export interface LocatorEx extends Locator {- _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }>;+ _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string }>;}export interface FrameEx extends Frame {- _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }>;+ _expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string }>;}interface APIResponseEx extends APIResponse {diff --git a/packages/playwright/src/matchers/toBeTruthy.ts b/packages/playwright/src/matchers/toBeTruthy.tsindex 3f6144eaf8..94da12644c 100644--- a/packages/playwright/src/matchers/toBeTruthy.ts+++ b/packages/playwright/src/matchers/toBeTruthy.ts@@ -15,7 +15,7 @@*/import { callLogText, expectTypes } from '../util';-import { kNoElementsFoundError, matcherHint } from './matcherHint';+import { matcherHint } from './matcherHint';import { runBrowserBackendOnError } from '../mcp/test/browserBackend';import type { MatcherResult } from './matcherHint';@@ -29,7 +29,7 @@ export async function toBeTruthy(receiverType: string,expected: string,arg: string,- query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, log?: string[], received?: any, timedOut?: boolean }>,+ query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, log?: string[], received?: any, timedOut?: boolean, errorMessage?: string }>,options: { timeout?: number } = {},): Promise<MatcherResult<any, any>> {expectTypes(receiver, [receiverType], matcherName);@@ -41,11 +41,7 @@ export async function toBeTruthy(const timeout = options.timeout ?? this.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;- });+ const { matches: pass, log, timedOut, received, errorMessage } = await query(!!this.isNot, timeout);if (pass === !this.isNot) {return {@@ -56,15 +52,14 @@ export async function toBeTruthy(};}- const notFound = received === kNoElementsFoundError ? received : undefined;let printedReceived: string | undefined;let printedExpected: string | undefined;if (pass) {printedExpected = `Expected: not ${expected}`;- printedReceived = `Received: ${notFound ? kNoElementsFoundError : expected}`;+ printedReceived = errorMessage ?? `Received: ${expected}`;} else {printedExpected = `Expected: ${expected}`;- printedReceived = `Received: ${notFound ? kNoElementsFoundError : received}`;+ printedReceived = errorMessage ?? `Received: ${received}`;}const message = () => {const header = matcherHint(this, receiver, matcherName, 'locator', arg, matcherOptions, timedOut ? timeout : undefined, `${printedExpected}\n${printedReceived}`);diff --git a/packages/playwright/src/matchers/toEqual.ts b/packages/playwright/src/matchers/toEqual.tsindex 1c4a0bf6c9..967778db5d 100644--- a/packages/playwright/src/matchers/toEqual.ts+++ b/packages/playwright/src/matchers/toEqual.ts@@ -33,7 +33,7 @@ export async function toEqual<T>(matcherName: string,receiver: Locator,receiverType: string,- query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }>,+ query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean, errorMessage?: string }>,expected: T,options: { timeout?: number, contains?: boolean } = {},messagePreventExtraStatIndent?: boolean@@ -48,11 +48,7 @@ export async function toEqual<T>(const timeout = options.timeout ?? this.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;- });+ const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);if (pass === !this.isNot) {return {@@ -68,7 +64,10 @@ export async function toEqual<T>(let printedDiff: string | undefined;if (pass) {printedExpected = `Expected: not ${this.utils.printExpected(expected)}`;- printedReceived = `Received: ${this.utils.printReceived(received)}`;+ printedReceived = errorMessage ?? `Received: ${this.utils.printReceived(received)}`;+ } else if (errorMessage) {+ printedExpected = `Expected: ${this.utils.printExpected(expected)}`;+ printedReceived = errorMessage;} else if (Array.isArray(expected) && Array.isArray(received)) {const normalizedExpected = expected.map((exp, index) => {const rec = received[index];diff --git a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts b/packages/playwright/src/matchers/toMatchAriaSnapshot.tsindex edb7a860ab..ef304fad46 100644--- a/packages/playwright/src/matchers/toMatchAriaSnapshot.ts+++ b/packages/playwright/src/matchers/toMatchAriaSnapshot.ts@@ -20,8 +20,7 @@ import path from 'path';import { escapeTemplateString, isString } from 'playwright-core/lib/utils';-import { kNoElementsFoundError, matcherHint } from './matcherHint';-import { EXPECTED_COLOR } from '../common/expectBundle';+import { matcherHint } from './matcherHint';import { callLogText, fileExistsAsync } from '../util';import { printReceivedStringContainExpectedSubstring } from './expect';import { currentTestInfo } from '../common/globals';@@ -89,18 +88,17 @@ export async function toMatchAriaSnapshot(}expected = unshift(expected);- const { matches: pass, received, log, timedOut } = await receiver._expect('to.match.aria', { expectedValue: expected, isNot: this.isNot, timeout });- const typedReceived = received as MatcherReceived | typeof kNoElementsFoundError;+ const { matches: pass, received, log, timedOut, errorMessage } = await receiver._expect('to.match.aria', { expectedValue: expected, isNot: this.isNot, timeout });+ const typedReceived = received as MatcherReceived;const matcherHintWithExpect = (expectedReceivedString: string) => {return matcherHint(this, receiver, matcherName, 'locator', undefined, matcherOptions, timedOut ? timeout : undefined, expectedReceivedString);};- const notFound = typedReceived === kNoElementsFoundError;- if (notFound) {+ if (errorMessage) {return {pass: this.isNot,- message: () => matcherHintWithExpect(`Expected: ${this.utils.printExpected(expected)}\nReceived: ${EXPECTED_COLOR('<element not found>')}`) + callLogText(log),+ message: () => matcherHintWithExpect(`Expected: ${this.utils.printExpected(expected)}\n${errorMessage}`) + callLogText(log),name: 'toMatchAriaSnapshot',expected,};@@ -109,12 +107,12 @@ export async function toMatchAriaSnapshot(const receivedText = typedReceived.raw;const message = () => {if (pass) {- const receivedString = notFound ? receivedText : printReceivedStringContainExpectedSubstring(receivedText, receivedText.indexOf(expected), expected.length);+ const receivedString = printReceivedStringContainExpectedSubstring(receivedText, receivedText.indexOf(expected), expected.length);const expectedReceivedString = `Expected: not ${this.utils.printExpected(expected)}\nReceived: ${receivedString}`;return matcherHintWithExpect(expectedReceivedString) + callLogText(log);} else {const labelExpected = `Expected`;- const expectedReceivedString = notFound ? `${labelExpected}: ${this.utils.printExpected(expected)}\nReceived: ${receivedText}` : this.utils.printDiffOrStringify(expected, receivedText, labelExpected, 'Received', false);+ const expectedReceivedString = this.utils.printDiffOrStringify(expected, receivedText, labelExpected, 'Received', false);return matcherHintWithExpect(expectedReceivedString) + callLogText(log);}};diff --git a/packages/playwright/src/matchers/toMatchText.ts b/packages/playwright/src/matchers/toMatchText.tsindex 04b4c84a74..1552022d98 100644--- a/packages/playwright/src/matchers/toMatchText.ts+++ b/packages/playwright/src/matchers/toMatchText.ts@@ -22,7 +22,7 @@ import {printReceivedStringContainExpectedResult,printReceivedStringContainExpectedSubstring} from './expect';-import { kNoElementsFoundError, matcherHint } from './matcherHint';+import { matcherHint } from './matcherHint';import { EXPECTED_COLOR } from '../common/expectBundle';import { runBrowserBackendOnError } from '../mcp/test/browserBackend';@@ -35,7 +35,7 @@ export async function toMatchText(matcherName: string,receiver: Locator | Page,receiverType: 'Locator' | 'Page',- query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, received?: string, log?: string[], timedOut?: boolean }>,+ query: (isNot: boolean, timeout: number) => Promise<{ matches: boolean, received?: string, log?: string[], timedOut?: boolean, errorMessage?: string }>,expected: string | RegExp,options: { timeout?: number, matchSubstring?: boolean, receiverLabel?: string } = {},): Promise<MatcherResult<string | RegExp, string>> {@@ -60,12 +60,7 @@ export async function toMatchText(const timeout = options.timeout ?? this.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;- });+ const { matches: pass, received, log, timedOut, errorMessage } = await query(!!this.isNot, timeout);if (pass === !this.isNot) {return {@@ -78,36 +73,33 @@ export async function toMatchText(const stringSubstring = options.matchSubstring ? 'substring' : 'string';const receivedString = received || '';- const notFound = received === kNoElementsFoundError;let printedReceived: string | undefined;let printedExpected: string | undefined;let printedDiff: string | undefined;if (pass) {if (typeof expected === 'string') {- if (notFound) {- printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;- printedReceived = `Received: ${received}`;+ printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;+ if (errorMessage) {+ printedReceived = errorMessage;} else {- printedExpected = `Expected ${stringSubstring}: not ${this.utils.printExpected(expected)}`;const formattedReceived = printReceivedStringContainExpectedSubstring(receivedString, receivedString.indexOf(expected), expected.length);printedReceived = `Received string: ${formattedReceived}`;}} else {- if (notFound) {- printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;- printedReceived = `Received: ${received}`;+ printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;+ if (errorMessage) {+ printedReceived = errorMessage;} else {- printedExpected = `Expected pattern: not ${this.utils.printExpected(expected)}`;const formattedReceived = printReceivedStringContainExpectedResult(receivedString, typeof expected.exec === 'function' ? expected.exec(receivedString) : null);printedReceived = `Received string: ${formattedReceived}`;}}} else {const labelExpected = `Expected ${typeof expected === 'string' ? stringSubstring : 'pattern'}`;- if (notFound) {+ if (errorMessage) {printedExpected = `${labelExpected}: ${this.utils.printExpected(expected)}`;- printedReceived = `Received: ${received}`;+ printedReceived = errorMessage;} else {printedDiff = this.utils.printDiffOrStringify(expected, receivedString, labelExpected, 'Received string', false);}diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex a4ff80f6ad..b1b179f8cb 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -3296,6 +3296,7 @@ export type FrameExpectResult = {matches: boolean,received?: SerializedValue,timedOut?: boolean,+ errorMessage?: string,log?: string[],};diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex 337488643b..fbe6aeda51 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -2803,6 +2803,7 @@ Frame:matches: booleanreceived: SerializedValue?timedOut: boolean?+ errorMessage: string?log:type: array?items: stringdiff --git a/tests/page/expect-boolean.spec.ts b/tests/page/expect-boolean.spec.tsindex 8f8a58c9d9..d9174b4b25 100644--- a/tests/page/expect-boolean.spec.ts+++ b/tests/page/expect-boolean.spec.ts@@ -125,7 +125,7 @@ Timeout: 1000ms`);Locator: locator('input2')Expected: not checked-Received: <element(s) not found>+Error: element(s) not foundTimeout: 1000ms`);expect(stripAnsi(error.message)).toContain(`- Expect "not toBeChecked" with timeout 1000ms`);expect(stripAnsi(error.message)).toContain(`- waiting for locator(\'input2\')`);@@ -468,7 +468,7 @@ test.describe('toBeHidden', () => {Locator: locator('button')Expected: not hidden-Received: <element(s) not found>+Error: element(s) not foundTimeout: 1000ms`);expect(stripAnsi(error.message)).toContain(`- Expect "not toBeHidden" with timeout 1000ms`);});diff --git a/tests/page/expect-matcher-result.spec.ts b/tests/page/expect-matcher-result.spec.tsindex 277a0efbcb..549df88e46 100644--- a/tests/page/expect-matcher-result.spec.ts+++ b/tests/page/expect-matcher-result.spec.ts@@ -77,7 +77,6 @@ test('toBeTruthy-based assertions should have matcher result', async ({ page })const e = await expect(page.locator('#node2')).toBeVisible({ timeout: 1 }).catch(e => e);e.matcherResult.message = stripAnsi(e.matcherResult.message);expect.soft(e.matcherResult).toEqual({- actual: '<element(s) not found>',expected: 'visible',message: expect.stringContaining(`expect(locator).toBeVisible() failed`),name: 'toBeVisible',@@ -90,7 +89,7 @@ test('toBeTruthy-based assertions should have matcher result', async ({ page })Locator: locator('#node2')Expected: visible-Received: <element(s) not found>+Error: element(s) not foundTimeout: 1msCall log`);diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.tsindex 7aa5a2f2a8..e7a91dd10f 100644--- a/tests/page/expect-misc.spec.ts+++ b/tests/page/expect-misc.spec.ts@@ -582,3 +582,17 @@ test('toHaveText that does not match should not produce logs twice', async ({ paexpect(error.message).not.toContain('locator resolved to');expect(error.message.replace(waitingForMessage, '<redacted>')).not.toContain(waitingForMessage);});++test('strict mode violation error format', async ({ page }) => {+ await page.setContent('<div>hello</div><div>hi</div>');+ const error = await expect(page.locator('div')).toBeVisible().catch(e => e);+ expect(error.message).toContain('Expected: visible');+ expect(error.message).toContain(`Error: strict mode violation: locator('div') resolved to 2 elements:`);+});++test('invalid selector error format', async ({ page }) => {+ await page.setContent('<div>hello</div><div>hi</div>');+ const error = await expect(page.locator('##')).toBeVisible().catch(e => e);+ expect(error.message).toContain('Expected: visible');+ expect(error.message).toContain(`Error: Unexpected token "#" while parsing css selector "##".`);+});diff --git a/tests/page/expect-timeout.spec.ts b/tests/page/expect-timeout.spec.tsindex 7143d309f8..b45a378aa5 100644--- a/tests/page/expect-timeout.spec.ts+++ b/tests/page/expect-timeout.spec.ts@@ -24,7 +24,7 @@ test('should print timed out error message', async ({ page }) => {Locator: locator('no-such-thing')Expected string: "hey"-Received: <element(s) not found>+Error: element(s) not foundTimeout: 1000ms`);});@@ -46,7 +46,7 @@ test('should print timed out error message with impossible timeout', async ({ paLocator: locator('no-such-thing')Expected string: "hey"-Received: <element(s) not found>+Error: element(s) not foundTimeout: 1ms`);});diff --git a/tests/page/expect-to-have-text.spec.ts b/tests/page/expect-to-have-text.spec.tsindex b1b19cc02a..17f510e665 100644--- a/tests/page/expect-to-have-text.spec.ts+++ b/tests/page/expect-to-have-text.spec.ts@@ -160,7 +160,7 @@ test.describe('not.toHaveText', () => {await page.setContent('<div>hello</div>');const error = await expect(page.locator('span')).not.toHaveText('hello', { timeout: 1000 }).catch(e => e);expect(stripAnsi(error.message)).toContain('Expected string: not "hello"');- expect(stripAnsi(error.message)).toContain('Received: <element(s) not found>');+ expect(stripAnsi(error.message)).toContain('Error: element(s) not found');expect(stripAnsi(error.message)).toContain('waiting for locator(\'span\')');});});diff --git a/tests/page/matchers.misc.spec.ts b/tests/page/matchers.misc.spec.tsindex 5f785f49a3..eb3b092a1e 100644--- a/tests/page/matchers.misc.spec.ts+++ b/tests/page/matchers.misc.spec.ts@@ -41,7 +41,7 @@ it('should print no-locator-resolved error when locator matcher did not resolveconst error = await matcher().catch(e => e);expect(error).toBeInstanceOf(Error);expect(error.message).toContain(`waiting for locator('.nonexisting')`);- expect(stripAnsi(error.message)).toMatch(/Received: ?"?<element\(s\) not found>/);+ expect(stripAnsi(error.message)).toContain('Error: element(s) not found');});}});diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.tsindex a5e5b40c20..fca4d09e39 100644--- a/tests/playwright-test/expect.spec.ts+++ b/tests/playwright-test/expect.spec.ts@@ -635,7 +635,7 @@ test('should print pending operations for toHaveText', async ({ runInlineTest })const output = result.output;expect(output).toContain(`expect(locator).toHaveText(expected)`);expect(output).toContain('Expected string: "Text"');- expect(output).toContain('Received: <element(s) not found>');+ expect(output).toContain('Error: element(s) not found');expect(output).toContain('waiting for locator(\'no-such-thing\')');});diff --git a/tests/playwright-test/update-aria-snapshot.spec.ts b/tests/playwright-test/update-aria-snapshot.spec.tsindex 78cdab3bab..203b5c27e4 100644--- a/tests/playwright-test/update-aria-snapshot.spec.ts+++ b/tests/playwright-test/update-aria-snapshot.spec.ts@@ -519,7 +519,7 @@ test('should not update snapshots when locator did not match', async ({ runInlinexpect(fs.existsSync(patchPath)).toBe(false);expect(result.output).not.toContain('New baselines created');expect(result.output).toContain('Expected: "- heading"');- expect(result.output).toContain('Received: <element not found>');+ expect(result.output).toContain('Error: element(s) not found');});test.describe('update-snapshots none', () => {