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

Fixes https://github.com/microsoft/playwright/issues/21846
This commit is contained in:
Andrey Lushnikov 2023-03-31 22:35:54 +00:00 committed by GitHub
parent 1fbefa694f
commit 5223c1ba39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -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]>

View File

@ -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 {

View File

@ -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.