api: remove timeout option from isVisible and isHidden methods (#7414)

It is unused and confusing.
This commit is contained in:
Dmitry Gozman 2021-07-01 13:30:16 -07:00 committed by GitHub
parent b9d3cccac0
commit 9f71c96740
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 120 additions and 95 deletions

View file

@ -910,8 +910,6 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
### param: Frame.isHidden.selector = %%-input-selector-%% ### param: Frame.isHidden.selector = %%-input-selector-%%
### option: Frame.isHidden.timeout = %%-input-timeout-%%
## async method: Frame.isVisible ## async method: Frame.isVisible
- returns: <[boolean]> - returns: <[boolean]>
@ -919,8 +917,6 @@ Returns whether the element is [visible](./actionability.md#visible). [`option:
### param: Frame.isVisible.selector = %%-input-selector-%% ### param: Frame.isVisible.selector = %%-input-selector-%%
### option: Frame.isVisible.timeout = %%-input-timeout-%%
## method: Frame.name ## method: Frame.name
- returns: <[string]> - returns: <[string]>

View file

@ -2016,8 +2016,6 @@ Returns whether the element is hidden, the opposite of [visible](./actionability
### param: Page.isHidden.selector = %%-input-selector-%% ### param: Page.isHidden.selector = %%-input-selector-%%
### option: Page.isHidden.timeout = %%-input-timeout-%%
## async method: Page.isVisible ## async method: Page.isVisible
- returns: <[boolean]> - returns: <[boolean]>
@ -2025,8 +2023,6 @@ Returns whether the element is [visible](./actionability.md#visible). [`option:
### param: Page.isVisible.selector = %%-input-selector-%% ### param: Page.isVisible.selector = %%-input-selector-%%
### option: Page.isVisible.timeout = %%-input-timeout-%%
## property: Page.keyboard ## property: Page.keyboard
- type: <[Keyboard]> - type: <[Keyboard]>

View file

@ -372,15 +372,15 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
}); });
} }
async isHidden(selector: string, options: channels.FrameIsHiddenOptions = {}): Promise<boolean> { async isHidden(selector: string): Promise<boolean> {
return this._wrapApiCall(async (channel: channels.FrameChannel) => { return this._wrapApiCall(async (channel: channels.FrameChannel) => {
return (await channel.isHidden({ selector, ...options })).value; return (await channel.isHidden({ selector })).value;
}); });
} }
async isVisible(selector: string, options: channels.FrameIsVisibleOptions = {}): Promise<boolean> { async isVisible(selector: string): Promise<boolean> {
return this._wrapApiCall(async (channel: channels.FrameChannel) => { return this._wrapApiCall(async (channel: channels.FrameChannel) => {
return (await channel.isVisible({ selector, ...options })).value; return (await channel.isVisible({ selector })).value;
}); });
} }

View file

@ -557,12 +557,12 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia
return this._mainFrame.isEnabled(selector, options); return this._mainFrame.isEnabled(selector, options);
} }
async isHidden(selector: string, options?: channels.FrameIsHiddenOptions): Promise<boolean> { async isHidden(selector: string): Promise<boolean> {
return this._mainFrame.isHidden(selector, options); return this._mainFrame.isHidden(selector);
} }
async isVisible(selector: string, options?: channels.FrameIsVisibleOptions): Promise<boolean> { async isVisible(selector: string): Promise<boolean> {
return this._mainFrame.isVisible(selector, options); return this._mainFrame.isVisible(selector);
} }
async hover(selector: string, options?: channels.FrameHoverOptions) { async hover(selector: string, options?: channels.FrameHoverOptions) {

View file

@ -175,11 +175,11 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
} }
async isHidden(params: channels.FrameIsHiddenParams, metadata: CallMetadata): Promise<channels.FrameIsHiddenResult> { async isHidden(params: channels.FrameIsHiddenParams, metadata: CallMetadata): Promise<channels.FrameIsHiddenResult> {
return { value: await this._frame.isHidden(metadata, params.selector, params) }; return { value: await this._frame.isHidden(metadata, params.selector) };
} }
async isVisible(params: channels.FrameIsVisibleParams, metadata: CallMetadata): Promise<channels.FrameIsVisibleResult> { async isVisible(params: channels.FrameIsVisibleParams, metadata: CallMetadata): Promise<channels.FrameIsVisibleResult> {
return { value: await this._frame.isVisible(metadata, params.selector, params) }; return { value: await this._frame.isVisible(metadata, params.selector) };
} }
async hover(params: channels.FrameHoverParams, metadata: CallMetadata): Promise<void> { async hover(params: channels.FrameHoverParams, metadata: CallMetadata): Promise<void> {

View file

@ -1627,20 +1627,18 @@ export type FrameIsEnabledResult = {
}; };
export type FrameIsHiddenParams = { export type FrameIsHiddenParams = {
selector: string, selector: string,
timeout?: number,
}; };
export type FrameIsHiddenOptions = { export type FrameIsHiddenOptions = {
timeout?: number,
}; };
export type FrameIsHiddenResult = { export type FrameIsHiddenResult = {
value: boolean, value: boolean,
}; };
export type FrameIsVisibleParams = { export type FrameIsVisibleParams = {
selector: string, selector: string,
timeout?: number,
}; };
export type FrameIsVisibleOptions = { export type FrameIsVisibleOptions = {
timeout?: number,
}; };
export type FrameIsVisibleResult = { export type FrameIsVisibleResult = {
value: boolean, value: boolean,
@ -3290,6 +3288,7 @@ export const commandsWithTracingSnapshots = new Set([
'Frame.isDisabled', 'Frame.isDisabled',
'Frame.isEnabled', 'Frame.isEnabled',
'Frame.isHidden', 'Frame.isHidden',
'Frame.isVisible',
'Frame.isEditable', 'Frame.isEditable',
'Frame.press', 'Frame.press',
'Frame.selectOption', 'Frame.selectOption',

View file

@ -1355,7 +1355,6 @@ Frame:
isHidden: isHidden:
parameters: parameters:
selector: string selector: string
timeout: number?
returns: returns:
value: boolean value: boolean
tracing: tracing:
@ -1364,9 +1363,10 @@ Frame:
isVisible: isVisible:
parameters: parameters:
selector: string selector: string
timeout: number?
returns: returns:
value: boolean value: boolean
tracing:
snapshot: true
isEditable: isEditable:
parameters: parameters:

View file

@ -669,11 +669,9 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
}); });
scheme.FrameIsHiddenParams = tObject({ scheme.FrameIsHiddenParams = tObject({
selector: tString, selector: tString,
timeout: tOptional(tNumber),
}); });
scheme.FrameIsVisibleParams = tObject({ scheme.FrameIsVisibleParams = tObject({
selector: tString, selector: tString,
timeout: tOptional(tNumber),
}); });
scheme.FrameIsEditableParams = tObject({ scheme.FrameIsEditableParams = tObject({
selector: tString, selector: tString,

View file

@ -1062,17 +1062,17 @@ export class Frame extends SdkObject {
return dom.throwFatalDOMError(dom.throwRetargetableDOMError(result)); return dom.throwFatalDOMError(dom.throwRetargetableDOMError(result));
} }
async isVisible(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> { async isVisible(metadata: CallMetadata, selector: string): Promise<boolean> {
const controller = new ProgressController(metadata, this); const controller = new ProgressController(metadata, this);
return controller.run(async progress => { return controller.run(async progress => {
progress.log(` checking visibility of "${selector}"`); progress.log(` checking visibility of "${selector}"`);
const element = await this.$(selector); const element = await this.$(selector);
return element ? await element.isVisible() : false; return element ? await element.isVisible() : false;
}, this._page._timeoutSettings.timeout(options)); }, this._page._timeoutSettings.timeout({}));
} }
async isHidden(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> { async isHidden(metadata: CallMetadata, selector: string): Promise<boolean> {
return !(await this.isVisible(metadata, selector, options)); return !(await this.isVisible(metadata, selector));
} }
async isDisabled(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> { async isDisabled(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {

122
types/types.d.ts vendored
View file

@ -367,6 +367,35 @@ export interface Page {
*/ */
exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>;
/**
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
* match any elements is considered hidden.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
*/
isHidden(selector: string): Promise<boolean>;
isHidden(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
/**
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
* considered not visible.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
*/
isVisible(selector: string): Promise<boolean>;
isVisible(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
/** /**
* Emitted when the page closes. * Emitted when the page closes.
*/ */
@ -2109,38 +2138,6 @@ export interface Page {
timeout?: number; timeout?: number;
}): Promise<boolean>; }): Promise<boolean>;
/**
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
* match any elements is considered hidden.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
* @param options
*/
isHidden(selector: string, options?: {
/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
*/
timeout?: number;
}): Promise<boolean>;
/**
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
* considered not visible.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
* @param options
*/
isVisible(selector: string, options?: {
/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
*/
timeout?: number;
}): Promise<boolean>;
keyboard: Keyboard; keyboard: Keyboard;
/** /**
@ -3556,6 +3553,35 @@ export interface Frame {
waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>; waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>; waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>; waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
/**
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
* match any elements is considered hidden.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
*/
isHidden(selector: string): Promise<boolean>;
isHidden(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
/**
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
* considered not visible.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
*/
isVisible(selector: string): Promise<boolean>;
isVisible(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
/** /**
* Returns the added tag when the script's onload fires or when the script content was injected into frame. * Returns the added tag when the script's onload fires or when the script content was injected into frame.
* *
@ -4161,38 +4187,6 @@ export interface Frame {
timeout?: number; timeout?: number;
}): Promise<boolean>; }): Promise<boolean>;
/**
* Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
* match any elements is considered hidden.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
* @param options
*/
isHidden(selector: string, options?: {
/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
*/
timeout?: number;
}): Promise<boolean>;
/**
* Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
* considered not visible.
* @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
* @param options
*/
isVisible(selector: string, options?: {
/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
*/
timeout?: number;
}): Promise<boolean>;
/** /**
* Returns frame's name attribute as specified in the tag. * Returns frame's name attribute as specified in the tag.
* *

View file

@ -59,6 +59,25 @@ export interface Page {
exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>; exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>;
isHidden(selector: string): Promise<boolean>;
isHidden(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
isVisible(selector: string): Promise<boolean>;
isVisible(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
} }
export interface Frame { export interface Frame {
@ -91,6 +110,25 @@ export interface Frame {
waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>; waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>; waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>; waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
isHidden(selector: string): Promise<boolean>;
isHidden(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
isVisible(selector: string): Promise<boolean>;
isVisible(selector: string, options?: {
/**
* Option `timeout` has no effect.
* @deprecated
*/
timeout?: number
}): Promise<boolean>;
} }
export interface BrowserContext { export interface BrowserContext {

View file

@ -130,6 +130,10 @@ playwright.chromium.launch().then(async browser => {
await page.emulateMedia({media: 'screen'}); await page.emulateMedia({media: 'screen'});
await page.pdf({ path: 'page.pdf' }); await page.pdf({ path: 'page.pdf' });
// Deprecated option still compiles.
await page.isVisible('div', { timeout: 123 });
await page.mainFrame().isHidden('div', { timeout: 123 });
await page.route('**/*', (route, interceptedRequest) => { await page.route('**/*', (route, interceptedRequest) => {
if ( if (
interceptedRequest.url().endsWith('.png') || interceptedRequest.url().endsWith('.png') ||