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
Revert "api: remove timeout option from isVisible and isHidden methods (#7414)" (#7600)
Dmitry Gozmand1170b30fc3f
diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.mdindex 83a33c7feb..d3456c693d 100644--- a/docs/src/api/class-frame.md+++ b/docs/src/api/class-frame.md@@ -910,6 +910,8 @@ 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]>@@ -917,6 +919,8 @@ 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 6cd459a569..d20b8ff4ed 100644--- a/docs/src/api/class-page.md+++ b/docs/src/api/class-page.md@@ -2018,6 +2018,8 @@ 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,6 +2027,8 @@ 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]>@@ -2623,7 +2627,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 6406f9df3d..8886961d0a 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): Promise<boolean> {+ async isHidden(selector: string, options: channels.FrameIsHiddenOptions = {}): Promise<boolean> {return this._wrapApiCall(async (channel: channels.FrameChannel) => {- return (await channel.isHidden({ selector })).value;+ return (await channel.isHidden({ selector, ...options })).value;});}- async isVisible(selector: string): Promise<boolean> {+ async isVisible(selector: string, options: channels.FrameIsVisibleOptions = {}): Promise<boolean> {return this._wrapApiCall(async (channel: channels.FrameChannel) => {- return (await channel.isVisible({ selector })).value;+ return (await channel.isVisible({ selector, ...options })).value;});}diff --git a/src/client/page.ts b/src/client/page.tsindex 10bab959c5..76024265f7 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): Promise<boolean> {- return this._mainFrame.isHidden(selector);+ async isHidden(selector: string, options?: channels.FrameIsHiddenOptions): Promise<boolean> {+ return this._mainFrame.isHidden(selector, options);}- async isVisible(selector: string): Promise<boolean> {- return this._mainFrame.isVisible(selector);+ async isVisible(selector: string, options?: channels.FrameIsVisibleOptions): Promise<boolean> {+ return this._mainFrame.isVisible(selector, options);}async hover(selector: string, options?: channels.FrameHoverOptions) {diff --git a/src/dispatchers/frameDispatcher.ts b/src/dispatchers/frameDispatcher.tsindex 843e0da1ab..f998cf8381 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) };+ return { value: await this._frame.isHidden(metadata, params.selector, params) };}async isVisible(params: channels.FrameIsVisibleParams, metadata: CallMetadata): Promise<channels.FrameIsVisibleResult> {- return { value: await this._frame.isVisible(metadata, params.selector) };+ return { value: await this._frame.isVisible(metadata, params.selector, params) };}async hover(params: channels.FrameHoverParams, metadata: CallMetadata): Promise<void> {diff --git a/src/protocol/channels.ts b/src/protocol/channels.tsindex 74367858e3..0fe8296ca5 100644--- a/src/protocol/channels.ts+++ b/src/protocol/channels.ts@@ -1631,18 +1631,20 @@ 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,@@ -3292,7 +3294,6 @@ 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 7d8e2e3af2..812b97e8ee 100644--- a/src/protocol/protocol.yml+++ b/src/protocol/protocol.yml@@ -1356,6 +1356,7 @@ Frame:isHidden:parameters:selector: string+ timeout: number?returns:value: booleantracing:@@ -1364,10 +1365,9 @@ 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 77b78c521a..a4355a13f0 100644--- a/src/protocol/validator.ts+++ b/src/protocol/validator.ts@@ -671,9 +671,11 @@ 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 36a4bfc9e0..3c514828bf 100644--- a/src/server/frames.ts+++ b/src/server/frames.ts@@ -1064,17 +1064,17 @@ export class Frame extends SdkObject {return dom.throwFatalDOMError(dom.throwRetargetableDOMError(result));}- async isVisible(metadata: CallMetadata, selector: string): Promise<boolean> {+ async isVisible(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): 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({}));+ }, this._page._timeoutSettings.timeout(options));}- async isHidden(metadata: CallMetadata, selector: string): Promise<boolean> {- return !(await this.isVisible(metadata, selector));+ async isHidden(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {+ return !(await this.isVisible(metadata, selector, options));}async isDisabled(metadata: CallMetadata, selector: string, options: types.TimeoutOptions = {}): Promise<boolean> {diff --git a/types/types.d.ts b/types/types.d.tsindex dc5002494a..1ab0cbe76a 100644--- a/types/types.d.ts+++ b/types/types.d.ts@@ -367,35 +367,6 @@ 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.*/@@ -1896,6 +1867,38 @@ 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;/**@@ -3313,35 +3316,6 @@ 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.*@@ -3947,6 +3921,38 @@ 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 4278954795..75a76c27e5 100644--- a/utils/generate_types/overrides.d.ts+++ b/utils/generate_types/overrides.d.ts@@ -59,25 +59,6 @@ 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 {@@ -110,25 +91,6 @@ 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 e7663122bb..fb08ac3782 100644--- a/utils/generate_types/test/test.ts+++ b/utils/generate_types/test/test.ts@@ -130,10 +130,6 @@ 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') ||