Skip to content

Commit 2859430

Browse files
committed
chore(expect): preserve received value on Frame.expect success
Restores `received` in the FrameExpect success response so matchers and trace viewer can use it. `toMatchAriaSnapshot` needs it to write rebaselines in `--update-snapshots=all` mode; the trace viewer's "Return value" section uses it to display the matched text.
1 parent 1817c11 commit 2859430

7 files changed

Lines changed: 37 additions & 9 deletions

File tree

packages/playwright-core/src/client/frame.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,12 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
492492
const params: channels.FrameExpectParams = { expression, ...options, isNot: !!options.isNot };
493493
params.expectedValue = serializeArgument(options.expectedValue);
494494
try {
495-
await this._channel.expect(params);
496-
return { matches: !params.isNot };
495+
const channelResult = await this._channel.expect(params);
496+
const received = channelResult.received ? {
497+
value: channelResult.received.value !== undefined ? parseResult(channelResult.received.value) : undefined,
498+
ariaSnapshot: channelResult.received.ariaSnapshot,
499+
} : undefined;
500+
return { matches: !params.isNot, received };
497501
} catch (e) {
498502
if (!(e instanceof PlaywrightError) || !e.details)
499503
throw e;

packages/playwright-core/src/protocol/validator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,12 @@ scheme.FrameExpectParams = tObject({
16201620
isNot: tBoolean,
16211621
timeout: tFloat,
16221622
});
1623-
scheme.FrameExpectResult = tOptional(tObject({}));
1623+
scheme.FrameExpectResult = tObject({
1624+
received: tOptional(tObject({
1625+
value: tOptional(tType('SerializedValue')),
1626+
ariaSnapshot: tOptional(tString),
1627+
})),
1628+
});
16241629
scheme.FrameExpectErrorDetails = tObject({
16251630
received: tOptional(tObject({
16261631
value: tOptional(tType('SerializedValue')),

packages/playwright-core/src/server/dispatchers/frameDispatcher.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,15 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameChannel, Br
280280
expectedValue = parseAriaSnapshotUnsafe(yaml, expectedValue);
281281
progress.log(`${renderTitleForCall(progress.metadata)}${params.timeout ? ` with timeout ${params.timeout}ms` : ''}`);
282282
try {
283-
await this._frame.expect(progress, params.selector, { ...params, expectedValue });
283+
const result = await this._frame.expect(progress, params.selector, { ...params, expectedValue });
284+
if (result.received === undefined)
285+
return {};
286+
return {
287+
received: {
288+
value: result.received.value !== undefined ? serializeResult(result.received.value) : undefined,
289+
ariaSnapshot: result.received.ariaSnapshot,
290+
},
291+
};
284292
} catch (e) {
285293
if (e instanceof ExpectError && e.details.received && 'value' in e.details.received)
286294
e.details.received.value = serializeResult(e.details.received.value);

packages/playwright-core/src/server/frames.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ export class Frame extends SdkObject<FrameEventMap> {
14661466
return progress.wait(timeout);
14671467
}
14681468

1469-
async expect(progress: Progress, selector: string | undefined, options: FrameExpectParams): Promise<void> {
1469+
async expect(progress: Progress, selector: string | undefined, options: FrameExpectParams): Promise<{ received?: ExpectReceived }> {
14701470
// `isSet` distinguishes "not collected yet" from "collected with received: undefined".
14711471
const lastIntermediateResult: { isSet: boolean, received?: ExpectReceived, errorMessage?: string } = { isSet: false };
14721472
try {
@@ -1481,15 +1481,15 @@ export class Frame extends SdkObject<FrameEventMap> {
14811481
try {
14821482
const resultOneShot = await this._expectInternal(progress, selector, options, lastIntermediateResult, true);
14831483
if (resultOneShot.matches !== options.isNot)
1484-
return;
1484+
return { received: resultOneShot.received };
14851485
} catch (e) {
14861486
if (this.isNonRetriableError(e))
14871487
throw e;
14881488
// Ignore any other errors from one-shot, we'll handle them during retries.
14891489
}
14901490

14911491
// Step 3: auto-retry expect with increasing timeouts. Bounded by the total remaining time.
1492-
await this.retryWithProgressAndBackoff(progress, async (progress, continuePolling) => {
1492+
const result = await this.retryWithProgressAndBackoff(progress, async (progress, continuePolling) => {
14931493
await this._page.performActionPreChecks(progress);
14941494
const { matches, received } = await this._expectInternal(progress, selector, options, lastIntermediateResult, false);
14951495
if (matches === options.isNot) {
@@ -1500,6 +1500,7 @@ export class Frame extends SdkObject<FrameEventMap> {
15001500
}
15011501
return { matches, received };
15021502
});
1503+
return { received: result.received };
15031504
} catch (e) {
15041505
let message = 'Expect failed';
15051506
const details: ExpectErrorDetails = {};

packages/protocol/spec/frame.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,12 @@ Frame:
764764
useInnerText: boolean?
765765
isNot: boolean
766766
timeout: float
767+
returns:
768+
received:
769+
type: object?
770+
properties:
771+
value: SerializedValue?
772+
ariaSnapshot: string?
767773
errorDetails:
768774
received:
769775
type: object?

packages/protocol/src/channels.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,12 @@ export type FrameExpectOptions = {
29612961
expectedValue?: SerializedArgument,
29622962
useInnerText?: boolean,
29632963
};
2964-
export type FrameExpectResult = void;
2964+
export type FrameExpectResult = {
2965+
received?: {
2966+
value?: SerializedValue,
2967+
ariaSnapshot?: string,
2968+
},
2969+
};
29652970
export type FrameExpectErrorDetails = {
29662971
received?: {
29672972
value?: SerializedValue,

tests/library/trace-viewer.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ test('should show params and return value', async ({ showTraceViewer }) => {
370370
/locator:locator\('button'\)/,
371371
/expression:"to.have.text"/,
372372
/timeout:10000/,
373-
/matches:true/,
374373
/received:"Click"/,
375374
]);
376375
});

0 commit comments

Comments
 (0)