Skip to content

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

chore(server): clean up action option types (#42902)

Dmitry Gozman5ce0bb49de95
diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts
index 073531eed4..674b8ab81f 100644
--- a/packages/playwright-core/src/server/dom.ts
+++ b/packages/playwright-core/src/server/dom.ts
@@ -540,13 +540,13 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
return this._retryPointerAction(progress, 'click', true /* waitForEnabled */, (progress, point) => this._page.mouse.click(progress, point.x, point.y, options), options, frameVisible);
}
- async dblclick(progress: Progress, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions): Promise<void> {
+ async dblclick(progress: Progress, options: types.MouseClickOptions & types.PointerActionWaitOptions): Promise<void> {
await this._markAsTargetElement(progress);
const result = await this._dblclick(progress, options, true /* frameVisible */);
return assertDone(throwRetargetableDOMError(result));
}
- _dblclick(progress: Progress, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions, frameVisible: boolean): Promise<'error:notconnected' | 'done'> {
+ _dblclick(progress: Progress, options: types.MouseClickOptions & types.PointerActionWaitOptions, frameVisible: boolean): Promise<'error:notconnected' | 'done'> {
return this._retryPointerAction(progress, 'dblclick', true /* waitForEnabled */, (progress, point) => this._page.mouse.click(progress, point.x, point.y, { ...options, clickCount: 2 }), { ...options, waitAfter: 'disabled' }, frameVisible);
}
@@ -648,7 +648,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
return assertDone(throwRetargetableDOMError(result));
}
- async _drop(progress: Progress, inputFileItems: InputFilesItems, data: { mimeType: string, value: string }[], options: types.PointerActionWaitOptions, frameVisible: boolean): Promise<'error:notconnected' | 'done'> {
+ async _drop(progress: Progress, inputFileItems: InputFilesItems, data: { mimeType: string, value: string }[], options: { position?: types.Point }, frameVisible: boolean): Promise<'error:notconnected' | 'done'> {
const { filePayloads, localPaths } = inputFileItems;
let payloads: { name: string, mimeType: string, buffer: string, lastModifiedMs?: number }[];
if (localPaths && !filePayloads) {
diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts
index f2cece2197..4af02632c2 100644
--- a/packages/playwright-core/src/server/frames.ts
+++ b/packages/playwright-core/src/server/frames.ts
@@ -894,7 +894,7 @@ export class Frame extends SdkObject<FrameEventMap> {
return scope ? scope._context.raceAgainstContextDestroyed(promise) : promise;
}
- async dispatchEvent(progress: Progress, selector: string, type: string, eventInit: Object = {}, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<void> {
+ async dispatchEvent(progress: Progress, selector: string, type: string, eventInit: Object = {}, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<void> {
await this._waitForFunctionOnSelector(progress, selector, (injectedScript, element, data) => {
injectedScript.dispatchEvent(element, data.type, data.eventInit);
return { result: undefined };
@@ -1253,7 +1253,7 @@ export class Frame extends SdkObject<FrameEventMap> {
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, { ...options, waitForFrameVisible: true }, (progress, handle, box, frameVisible) => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter }, frameVisible)));
}
- async dblclick(progress: Progress, selector: string, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions) {
+ async dblclick(progress: Progress, selector: string, options: types.MouseClickOptions & types.PointerActionWaitOptions) {
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, { ...options, waitForFrameVisible: true }, (progress, handle, box, frameVisible) => handle._dblclick(progress, options, frameVisible)));
}
@@ -1329,12 +1329,12 @@ export class Frame extends SdkObject<FrameEventMap> {
return { resolvedSelector };
}
- async textContent(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {
+ async textContent(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<string | null> {
const { result } = await this._waitForFunctionOnSelector(progress, selector, (injected, element) => ({ result: element.textContent }), undefined, options, scope);
return result;
}
- async innerText(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {
+ async innerText(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<string> {
const { result } = await this._waitForFunctionOnSelector(progress, selector, (injectedScript, element) => {
if (element.namespaceURI !== 'http://www.w3.org/1999/xhtml')
throw injectedScript.createStacklessError('Node is not an HTMLElement');
@@ -1343,12 +1343,12 @@ export class Frame extends SdkObject<FrameEventMap> {
return result;
}
- async innerHTML(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {
+ async innerHTML(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<string> {
const { result } = await this._waitForFunctionOnSelector(progress, selector, (injected, element) => ({ result: element.innerHTML }), undefined, options, scope);
return result;
}
- async getAttribute(progress: Progress, selector: string, name: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {
+ async getAttribute(progress: Progress, selector: string, name: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<string | null> {
const { result } = await this._waitForFunctionOnSelector(progress, selector, (injected, element, data) => ({ result: element.getAttribute(data.name) }), { name }, options, scope);
return result;
}
@@ -1363,7 +1363,7 @@ export class Frame extends SdkObject<FrameEventMap> {
return result;
}
- private async _elementState(progress: Progress, selector: string, state: Exclude<ElementStateWithoutStable, 'visible' | 'hidden'>, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {
+ private async _elementState(progress: Progress, selector: string, state: Exclude<ElementStateWithoutStable, 'visible' | 'hidden'>, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<boolean> {
const { result } = await this._waitForFunctionOnSelector(progress, selector, (injected, element, data) => {
return { result: injected.elementState(element, data.state) };
}, { state }, options, scope);
@@ -1396,19 +1396,19 @@ export class Frame extends SdkObject<FrameEventMap> {
return !(await this.isVisible(progress, selector, options, scope));
}
- async isDisabled(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {
+ async isDisabled(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<boolean> {
return this._elementState(progress, selector, 'disabled', options, scope);
}
- async isEnabled(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {
+ async isEnabled(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<boolean> {
return this._elementState(progress, selector, 'enabled', options, scope);
}
- async isEditable(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {
+ async isEditable(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<boolean> {
return this._elementState(progress, selector, 'editable', options, scope);
}
- async isChecked(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {
+ async isChecked(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<boolean> {
return this._elementState(progress, selector, 'checked', options, scope);
}
@@ -1425,7 +1425,7 @@ export class Frame extends SdkObject<FrameEventMap> {
return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params, (progress, handle, box) => handle._setInputFiles(progress, inputFileItems, box)));
}
- async drop(progress: Progress, selector: string, params: Omit<channels.FrameDropParams, 'timeout' | 'selector'>, options: types.PointerActionWaitOptions): Promise<void> {
+ async drop(progress: Progress, selector: string, params: Omit<channels.FrameDropParams, 'timeout' | 'selector'>, options: types.StrictOptions & { position?: types.Point }): Promise<void> {
const hasFiles = !!(params.payloads?.length || params.localPaths?.length || params.streams?.length);
const hasData = !!params.data?.length;
if (!hasFiles && !hasData)
diff --git a/packages/playwright-core/src/server/types.ts b/packages/playwright-core/src/server/types.ts
index abbd43c1f9..f5317a24ae 100644
--- a/packages/playwright-core/src/server/types.ts
+++ b/packages/playwright-core/src/server/types.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-import type { HeadersArray, Point, Size } from '@isomorphic/types';
+import type { HeadersArray, Point } from '@isomorphic/types';
export type { HeadersArray, Point, Quad, Rect, Size, DeviceDescriptor, Devices } from '@isomorphic/types';
import type * as channels from './channels';
import type { ProxySettings } from '@utils/network';
@@ -24,8 +24,6 @@ export type StrictOptions = {
strict?: boolean,
};
-export type QueryOnSelectorOptions = StrictOptions;
-
export type WaitForElementOptions = StrictOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' } & { omitReturnValue?: boolean };
export type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
@@ -37,17 +35,11 @@ export type NavigateOptions = {
export type CommonActionOptions = StrictOptions & {
force?: boolean,
- scroll?: 'auto' | 'none',
};
export type PointerActionWaitOptions = CommonActionOptions & {
trial?: boolean;
-};
-
-export type VideoOptions = {
- width: number,
- height: number,
- outputFile: string,
+ scroll?: 'auto' | 'none';
};
export type ScreencastFrame = {
@@ -64,6 +56,7 @@ export type Geolocation = {
};
export type SelectOption = {
+ valueOrLabel?: string;
value?: string;
label?: string;
index?: number;
@@ -108,11 +101,7 @@ export type MouseClickOptions = PointerActionOptions & {
delay?: number;
button?: MouseButton;
clickCount?: number;
-};
-
-export type MouseMultiClickOptions = PointerActionOptions & {
- delay?: number;
- button?: MouseButton;
+ steps?: number;
};
export type World = 'main' | 'utility';
@@ -136,8 +125,6 @@ export type NormalizedContinueOverrides = {
isFallback: boolean,
};
-export type EmulatedSize = { viewport: Size, screen: Size };
-
export type LaunchOptions = Omit<channels.BrowserTypeLaunchParams, 'timeout'> & {
proxyOverride?: ProxySettings,
socksProxyPort?: number,