Skip to content

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

chore: move Frame.waitForTimeout to the server side (#9053)

Max Schmittd354d14fb91f
diff --git a/src/client/frame.ts b/src/client/frame.ts
index e03ceb8d18..6e2e2cb83b 100644
--- a/src/client/frame.ts
+++ b/src/client/frame.ts
@@ -446,7 +446,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
async waitForTimeout(timeout: number) {
return this._wrapApiCall(async (channel: channels.FrameChannel) => {
- await new Promise(fulfill => setTimeout(fulfill, timeout));
+ await channel.waitForTimeout({ timeout });
});
}
diff --git a/src/dispatchers/frameDispatcher.ts b/src/dispatchers/frameDispatcher.ts
index 1c2d42d381..25af5311db 100644
--- a/src/dispatchers/frameDispatcher.ts
+++ b/src/dispatchers/frameDispatcher.ts
@@ -215,6 +215,10 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
return await this._frame.uncheck(metadata, params.selector, params);
}
+ async waitForTimeout(params: channels.FrameWaitForTimeoutParams, metadata: CallMetadata): Promise<void> {
+ return await this._frame.waitForTimeout(metadata, params.timeout);
+ }
+
async waitForFunction(params: channels.FrameWaitForFunctionParams, metadata: CallMetadata): Promise<channels.FrameWaitForFunctionResult> {
return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame._waitForFunctionExpression(metadata, params.expression, params.isFunction, parseArgument(params.arg), params)) };
}
diff --git a/src/protocol/channels.ts b/src/protocol/channels.ts
index ed2e560422..a647917f90 100644
--- a/src/protocol/channels.ts
+++ b/src/protocol/channels.ts
@@ -1578,6 +1578,7 @@ export interface FrameChannel extends Channel {
title(params?: FrameTitleParams, metadata?: Metadata): Promise<FrameTitleResult>;
type(params: FrameTypeParams, metadata?: Metadata): Promise<FrameTypeResult>;
uncheck(params: FrameUncheckParams, metadata?: Metadata): Promise<FrameUncheckResult>;
+ waitForTimeout(params: FrameWaitForTimeoutParams, metadata?: Metadata): Promise<FrameWaitForTimeoutResult>;
waitForFunction(params: FrameWaitForFunctionParams, metadata?: Metadata): Promise<FrameWaitForFunctionResult>;
waitForSelector(params: FrameWaitForSelectorParams, metadata?: Metadata): Promise<FrameWaitForSelectorResult>;
}
@@ -2107,6 +2108,13 @@ export type FrameUncheckOptions = {
trial?: boolean,
};
export type FrameUncheckResult = void;
+export type FrameWaitForTimeoutParams = {
+ timeout: number,
+};
+export type FrameWaitForTimeoutOptions = {
+
+};
+export type FrameWaitForTimeoutResult = void;
export type FrameWaitForFunctionParams = {
expression: string,
isFunction?: boolean,
@@ -3695,6 +3703,7 @@ export const commandsWithTracingSnapshots = new Set([
'Frame.textContent',
'Frame.type',
'Frame.uncheck',
+ 'Frame.waitForTimeout',
'Frame.waitForFunction',
'Frame.waitForSelector',
'JSHandle.evaluateExpression',
diff --git a/src/protocol/protocol.yml b/src/protocol/protocol.yml
index 1ab1d1de1a..628a947958 100644
--- a/src/protocol/protocol.yml
+++ b/src/protocol/protocol.yml
@@ -1687,6 +1687,12 @@ Frame:
snapshot: true
pausesBeforeInput: true
+ waitForTimeout:
+ parameters:
+ timeout: number
+ tracing:
+ snapshot: true
+
waitForFunction:
parameters:
expression: string
diff --git a/src/protocol/validator.ts b/src/protocol/validator.ts
index 6ea42a89f4..900fb99a62 100644
--- a/src/protocol/validator.ts
+++ b/src/protocol/validator.ts
@@ -846,6 +846,9 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
timeout: tOptional(tNumber),
trial: tOptional(tBoolean),
});
+ scheme.FrameWaitForTimeoutParams = tObject({
+ timeout: tNumber,
+ });
scheme.FrameWaitForFunctionParams = tObject({
expression: tString,
isFunction: tOptional(tBoolean),
diff --git a/src/server/frames.ts b/src/server/frames.ts
index c5970ab8af..72879510d2 100644
--- a/src/server/frames.ts
+++ b/src/server/frames.ts
@@ -1175,6 +1175,13 @@ export class Frame extends SdkObject {
}, this._page._timeoutSettings.timeout(options));
}
+ async waitForTimeout(metadata: CallMetadata, timeout: number) {
+ const controller = new ProgressController(metadata, this);
+ return controller.run(async () => {
+ await new Promise(resolve => setTimeout(resolve, timeout));
+ });
+ }
+
async _waitForFunctionExpression<R>(metadata: CallMetadata, expression: string, isFunction: boolean | undefined, arg: any, options: types.WaitForFunctionOptions, world: types.World = 'main'): Promise<js.SmartHandle<R>> {
const controller = new ProgressController(metadata, this);
if (typeof options.pollingInterval === 'number')
diff --git a/tests/trace-viewer/trace-viewer.spec.ts b/tests/trace-viewer/trace-viewer.spec.ts
index 3c4c575a10..7557d16164 100644
--- a/tests/trace-viewer/trace-viewer.spec.ts
+++ b/tests/trace-viewer/trace-viewer.spec.ts
@@ -159,6 +159,7 @@ test('should open simple trace viewer', async ({ showTraceViewer }) => {
/page.evaluate— \d+ms/,
/page.click"Click"— \d+ms/,
/page.waitForNavigation— \d+ms/,
+ /page.waitForTimeout— \d+ms/,
/page.gotohttp:\/\/localhost:\d+\/frames\/frame.html— \d+ms/,
/page.setViewportSize— \d+ms/,
/page.hoverbody— \d+ms/,