Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
api: remove timeout option from isVisible and isHidden methods (#7414)
Dmitry Gozman9f71c9674064
diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.mdindex d3456c693d..83a33c7feb 100644--- a/docs/src/api/class-frame.md+++ b/docs/src/api/class-frame.md@@ -910,8 +910,6 @@ Returns whether the element is hidden, the opposite of [visible](./actionability### param: Frame.isHidden.selector = %%-input-selector-%%-### option: Frame.isHidden.timeout = %%-input-timeout-%%-## async method: Frame.isVisible- returns: <[boolean]>@@ -919,8 +917,6 @@ Returns whether the element is [visible](./actionability.md#visible). [`option:### param: Frame.isVisible.selector = %%-input-selector-%%-### option: Frame.isVisible.timeout = %%-input-timeout-%%-## method: Frame.name- returns: <[string]>diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.mdindex 854abe0cd0..aff6b9d585 100644--- a/docs/src/api/class-page.md+++ b/docs/src/api/class-page.md@@ -2016,8 +2016,6 @@ Returns whether the element is hidden, the opposite of [visible](./actionability### param: Page.isHidden.selector = %%-input-selector-%%-### option: Page.isHidden.timeout = %%-input-timeout-%%-## async method: Page.isVisible- returns: <[boolean]>@@ -2025,8 +2023,6 @@ Returns whether the element is [visible](./actionability.md#visible). [`option:### param: Page.isVisible.selector = %%-input-selector-%%-### option: Page.isVisible.timeout = %%-input-timeout-%%-## property: Page.keyboard- type: <[Keyboard]>@@ -2624,7 +2620,7 @@ page.select_option("select#colors", value=["red", "green", "blue"])await page.SelectOptionAsync("select#colors", new[] { "blue" });// single selection matching both the value and the labelawait page.SelectOptionAsync("select#colors", new[] { new SelectOptionValue() { Label = "blue" } });-// multiple+// multipleawait page.SelectOptionAsync("select#colors", new[] { "red", "green", "blue" });```diff --git a/src/client/frame.ts b/src/client/frame.tsindex 1a9ac172b5..4af1fddcbc 100644--- a/src/client/frame.ts+++ b/src/client/frame.ts@@ -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 (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 (await channel.isVisible({ selector, ...options })).value;+ return (await channel.isVisible({ selector })).value;});}diff --git a/src/client/page.ts b/src/client/page.tsindex 93c0c369e9..929f5a6fc3 100644--- a/src/client/page.ts+++ b/src/client/page.ts@@ -557,12 +557,12 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitiareturn this._mainFrame.isEnabled(selector, options);}- async isHidden(selector: string, options?: channels.FrameIsHiddenOptions): Promise<boolean> {- return this._mainFrame.isHidden(selector, options);+ async isHidden(selector: string): Promise<boolean> {+ return this._mainFrame.isHidden(selector);}- async isVisible(selector: string, options?: channels.FrameIsVisibleOptions): Promise<boolean> {- return this._mainFrame.isVisible(selector, options);+ async isVisible(selector: string): Promise<boolean> {+ return this._mainFrame.isVisible(selector);}async hover(selector: string, options?: channels.FrameHoverOptions) {diff --git a/src/dispatchers/frameDispatcher.ts b/src/dispatchers/frameDispatcher.tsindex f998cf8381..843e0da1ab 100644--- a/src/dispatchers/frameDispatcher.ts+++ b/src/dispatchers/frameDispatcher.ts@@ -175,11 +175,11 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer}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> {- 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> {diff --git a/src/protocol/channels.ts b/src/protocol/channels.tsindex f8e1372588..cd53d5dfd8 100644--- a/src/protocol/channels.ts+++ b/src/protocol/channels.ts@@ -1627,20 +1627,18 @@ export type FrameIsEnabledResult = {};export type FrameIsHiddenParams = {selector: string,- timeout?: number,};export type FrameIsHiddenOptions = {- timeout?: number,+};export type FrameIsHiddenResult = {value: boolean,};export type FrameIsVisibleParams = {selector: string,- timeout?: number,};export type FrameIsVisibleOptions = {- timeout?: number,+};export type FrameIsVisibleResult = {value: boolean,@@ -3290,6 +3288,7 @@ export const commandsWithTracingSnapshots = new Set(['Frame.isDisabled','Frame.isEnabled','Frame.isHidden',+ 'Frame.isVisible','Frame.isEditable','Frame.press','Frame.selectOption',diff --git a/src/protocol/protocol.yml b/src/protocol/protocol.ymlindex e4999a8770..535257c220 100644--- a/src/protocol/protocol.yml+++ b/src/protocol/protocol.yml@@ -1355,7 +1355,6 @@ Frame:isHidden:parameters:selector: string- timeout: number?returns:value: booleantracing:@@ -1364,9 +1363,10 @@ Frame:isVisible:parameters:selector: string- timeout: number?returns:value: boolean+ tracing:+ snapshot: trueisEditable:parameters:diff --git a/src/protocol/validator.ts b/src/protocol/validator.tsindex 9491f90e26..603dd56568 100644--- a/src/protocol/validator.ts+++ b/src/protocol/validator.ts@@ -669,11 +669,9 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {});scheme.FrameIsHiddenParams = tObject({selector: tString,- timeout: tOptional(tNumber),});scheme.FrameIsVisibleParams = tObject({selector: tString,- timeout: tOptional(tNumber),});scheme.FrameIsEditableParams = tObject({selector: tString,diff --git a/src/server/frames.ts b/src/server/frames.tsindex e53ae48fc8..356e744f93 100644--- a/src/server/frames.ts+++ b/src/server/frames.ts@@ -1062,17 +1062,17 @@ export class Frame extends SdkObject {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);return controller.run(async progress => {progress.log(` checking visibility of "${selector}"`);const element = await this.$(selector);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> {- return !(await this.isVisible(metadata, selector, options));+ async isHidden(metadata: CallMetadata, selector: string): Promise<boolean> {+ return !(await this.isVisible(metadata, selector));}async isDisabled(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {diff --git a/types/types.d.ts b/types/types.d.tsindex 90d47f1f50..23939cf045 100644--- a/types/types.d.ts+++ b/types/types.d.ts@@ -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, ...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.*/@@ -2109,38 +2138,6 @@ export interface Page {timeout?: number;}): 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;/**@@ -3556,6 +3553,35 @@ export interface Frame {waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;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.*@@ -4161,38 +4187,6 @@ export interface Frame {timeout?: number;}): 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.*diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.tsindex 75a76c27e5..4278954795 100644--- a/utils/generate_types/overrides.d.ts+++ b/utils/generate_types/overrides.d.ts@@ -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, ...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 {@@ -91,6 +110,25 @@ export interface Frame {waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;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 {diff --git a/utils/generate_types/test/test.ts b/utils/generate_types/test/test.tsindex fb08ac3782..e7663122bb 100644--- a/utils/generate_types/test/test.ts+++ b/utils/generate_types/test/test.ts@@ -130,6 +130,10 @@ playwright.chromium.launch().then(async browser => {await page.emulateMedia({media: 'screen'});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) => {if (interceptedRequest.url().endsWith('.png') ||