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

This commit is contained in:
Max Schmitt 2021-09-21 22:06:14 +02:00 committed by GitHub
parent 854cf9c25c
commit d354d14fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 1 deletions

View File

@ -446,7 +446,7 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
async waitForTimeout(timeout: number) { async waitForTimeout(timeout: number) {
return this._wrapApiCall(async (channel: channels.FrameChannel) => { return this._wrapApiCall(async (channel: channels.FrameChannel) => {
await new Promise(fulfill => setTimeout(fulfill, timeout)); await channel.waitForTimeout({ timeout });
}); });
} }

View File

@ -215,6 +215,10 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
return await this._frame.uncheck(metadata, params.selector, params); 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> { 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)) }; return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame._waitForFunctionExpression(metadata, params.expression, params.isFunction, parseArgument(params.arg), params)) };
} }

View File

@ -1578,6 +1578,7 @@ export interface FrameChannel extends Channel {
title(params?: FrameTitleParams, metadata?: Metadata): Promise<FrameTitleResult>; title(params?: FrameTitleParams, metadata?: Metadata): Promise<FrameTitleResult>;
type(params: FrameTypeParams, metadata?: Metadata): Promise<FrameTypeResult>; type(params: FrameTypeParams, metadata?: Metadata): Promise<FrameTypeResult>;
uncheck(params: FrameUncheckParams, metadata?: Metadata): Promise<FrameUncheckResult>; uncheck(params: FrameUncheckParams, metadata?: Metadata): Promise<FrameUncheckResult>;
waitForTimeout(params: FrameWaitForTimeoutParams, metadata?: Metadata): Promise<FrameWaitForTimeoutResult>;
waitForFunction(params: FrameWaitForFunctionParams, metadata?: Metadata): Promise<FrameWaitForFunctionResult>; waitForFunction(params: FrameWaitForFunctionParams, metadata?: Metadata): Promise<FrameWaitForFunctionResult>;
waitForSelector(params: FrameWaitForSelectorParams, metadata?: Metadata): Promise<FrameWaitForSelectorResult>; waitForSelector(params: FrameWaitForSelectorParams, metadata?: Metadata): Promise<FrameWaitForSelectorResult>;
} }
@ -2107,6 +2108,13 @@ export type FrameUncheckOptions = {
trial?: boolean, trial?: boolean,
}; };
export type FrameUncheckResult = void; export type FrameUncheckResult = void;
export type FrameWaitForTimeoutParams = {
timeout: number,
};
export type FrameWaitForTimeoutOptions = {
};
export type FrameWaitForTimeoutResult = void;
export type FrameWaitForFunctionParams = { export type FrameWaitForFunctionParams = {
expression: string, expression: string,
isFunction?: boolean, isFunction?: boolean,
@ -3695,6 +3703,7 @@ export const commandsWithTracingSnapshots = new Set([
'Frame.textContent', 'Frame.textContent',
'Frame.type', 'Frame.type',
'Frame.uncheck', 'Frame.uncheck',
'Frame.waitForTimeout',
'Frame.waitForFunction', 'Frame.waitForFunction',
'Frame.waitForSelector', 'Frame.waitForSelector',
'JSHandle.evaluateExpression', 'JSHandle.evaluateExpression',

View File

@ -1687,6 +1687,12 @@ Frame:
snapshot: true snapshot: true
pausesBeforeInput: true pausesBeforeInput: true
waitForTimeout:
parameters:
timeout: number
tracing:
snapshot: true
waitForFunction: waitForFunction:
parameters: parameters:
expression: string expression: string

View File

@ -846,6 +846,9 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
timeout: tOptional(tNumber), timeout: tOptional(tNumber),
trial: tOptional(tBoolean), trial: tOptional(tBoolean),
}); });
scheme.FrameWaitForTimeoutParams = tObject({
timeout: tNumber,
});
scheme.FrameWaitForFunctionParams = tObject({ scheme.FrameWaitForFunctionParams = tObject({
expression: tString, expression: tString,
isFunction: tOptional(tBoolean), isFunction: tOptional(tBoolean),

View File

@ -1175,6 +1175,13 @@ export class Frame extends SdkObject {
}, this._page._timeoutSettings.timeout(options)); }, 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>> { 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); const controller = new ProgressController(metadata, this);
if (typeof options.pollingInterval === 'number') if (typeof options.pollingInterval === 'number')

View File

@ -159,6 +159,7 @@ test('should open simple trace viewer', async ({ showTraceViewer }) => {
/page.evaluate— \d+ms/, /page.evaluate— \d+ms/,
/page.click"Click"— \d+ms/, /page.click"Click"— \d+ms/,
/page.waitForNavigation— \d+ms/, /page.waitForNavigation— \d+ms/,
/page.waitForTimeout— \d+ms/,
/page.gotohttp:\/\/localhost:\d+\/frames\/frame.html— \d+ms/, /page.gotohttp:\/\/localhost:\d+\/frames\/frame.html— \d+ms/,
/page.setViewportSize— \d+ms/, /page.setViewportSize— \d+ms/,
/page.hoverbody— \d+ms/, /page.hoverbody— \d+ms/,