Skip to content

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

feat: add timeout to `electron.firstWindow()` method (#21863)

Andrey Lushnikov5223c1ba3911
diff --git a/docs/src/api/class-electronapplication.md b/docs/src/api/class-electronapplication.md
index 6881bfee83..e848f4a6ab 100644
--- a/docs/src/api/class-electronapplication.md
+++ b/docs/src/api/class-electronapplication.md
@@ -135,6 +135,14 @@ Convenience method that waits for the first application window to be opened.
// ...
```
+### option: ElectronApplication.firstWindow.timeout
+* since: v1.33
+- `timeout` ?<[float]>
+
+Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds).
+Pass `0` to disable timeout. The default value can be changed by using the
+[`method: BrowserContext.setDefaultTimeout`].
+
## method: ElectronApplication.process
* since: v1.21
- returns: <[ChildProcess]>
diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts
index dfdfbb8664..2a4d2d7f3e 100644
--- a/packages/playwright-core/src/client/electron.ts
+++ b/packages/playwright-core/src/client/electron.ts
@@ -95,10 +95,10 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
return [...this._windows];
}
- async firstWindow(): Promise<Page> {
+ async firstWindow(options?: { timeout?: number }): Promise<Page> {
if (this._windows.size)
return this._windows.values().next().value;
- return this.waitForEvent('window');
+ return this.waitForEvent('window', options);
}
context(): BrowserContext {
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 0594a9a1b6..99337e9769 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -13402,8 +13402,16 @@ export interface ElectronApplication {
* // ...
* ```
*
+ * @param options
*/
- firstWindow(): Promise<Page>;
+ firstWindow(options?: {
+ /**
+ * Maximum time to wait for in milliseconds. Defaults to `30000` (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).
+ */
+ timeout?: number;
+ }): Promise<Page>;
/**
* Returns the main process for this Electron Application.