From 64b4ac1732697044aff4d83b29065a0337848803 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 10 May 2024 15:32:01 -0700 Subject: [PATCH] fix(electron): record har file (#30748) Fixes https://github.com/microsoft/playwright/issues/30747 --- packages/playwright-core/src/client/electron.ts | 8 ++------ packages/playwright-core/src/protocol/validator.ts | 2 -- packages/protocol/src/channels.ts | 4 ---- packages/protocol/src/protocol.yml | 2 -- tests/electron/electron-app.spec.ts | 12 ++++++++++++ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index f20bbfba19db1..a9e90b77f2f1b 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -57,7 +57,7 @@ export class Electron extends ChannelOwner implements tracesDir: options.tracesDir, }; const app = ElectronApplication.from((await this._channel.launch(params)).electronApplication); - app._context._options = params; + app._context._setOptions(params, options); return app; } } @@ -66,7 +66,6 @@ export class ElectronApplication extends ChannelOwner(); private _timeoutSettings = new TimeoutSettings(); - private _isClosed = false; static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication { return (electronApplication as any)._object; @@ -79,7 +78,6 @@ export class ElectronApplication extends ChannelOwner this._onPage(page)); this._channel.on('close', () => { - this._isClosed = true; this.emit(Events.ElectronApplication.Close); }); this._channel.on('console', event => this.emit(Events.ElectronApplication.Console, new ConsoleMessage(event))); @@ -118,9 +116,7 @@ export class ElectronApplication extends ChannelOwner {}); + await this._context.close().catch(() => {}); } async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise { diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts index 5e316402247a5..f97cf109699c8 100644 --- a/packages/playwright-core/src/protocol/validator.ts +++ b/packages/playwright-core/src/protocol/validator.ts @@ -2313,8 +2313,6 @@ scheme.ElectronApplicationUpdateSubscriptionParams = tObject({ enabled: tBoolean, }); scheme.ElectronApplicationUpdateSubscriptionResult = tOptional(tObject({})); -scheme.ElectronApplicationCloseParams = tOptional(tObject({})); -scheme.ElectronApplicationCloseResult = tOptional(tObject({})); scheme.AndroidInitializer = tOptional(tObject({})); scheme.AndroidDevicesParams = tObject({ host: tOptional(tString), diff --git a/packages/protocol/src/channels.ts b/packages/protocol/src/channels.ts index 7e683b9161e93..2024e02b56f2d 100644 --- a/packages/protocol/src/channels.ts +++ b/packages/protocol/src/channels.ts @@ -4124,7 +4124,6 @@ export interface ElectronApplicationChannel extends ElectronApplicationEventTarg evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: CallMetadata): Promise; evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise; updateSubscription(params: ElectronApplicationUpdateSubscriptionParams, metadata?: CallMetadata): Promise; - close(params?: ElectronApplicationCloseParams, metadata?: CallMetadata): Promise; } export type ElectronApplicationCloseEvent = {}; export type ElectronApplicationConsoleEvent = { @@ -4176,9 +4175,6 @@ export type ElectronApplicationUpdateSubscriptionOptions = { }; export type ElectronApplicationUpdateSubscriptionResult = void; -export type ElectronApplicationCloseParams = {}; -export type ElectronApplicationCloseOptions = {}; -export type ElectronApplicationCloseResult = void; export interface ElectronApplicationEvents { 'close': ElectronApplicationCloseEvent; diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.yml index 8ffe531754819..d3b5f9d00c556 100644 --- a/packages/protocol/src/protocol.yml +++ b/packages/protocol/src/protocol.yml @@ -3243,8 +3243,6 @@ ElectronApplication: - console enabled: boolean - close: - events: close: console: diff --git a/tests/electron/electron-app.spec.ts b/tests/electron/electron-app.spec.ts index 0ecfb2b42d586..37bb69ea9ef84 100644 --- a/tests/electron/electron-app.spec.ts +++ b/tests/electron/electron-app.spec.ts @@ -261,6 +261,18 @@ test('should record video', async ({ launchElectronApp }, testInfo) => { expect(fs.statSync(videoPath).size).toBeGreaterThan(0); }); +test('should record har', async ({ launchElectronApp, server }, testInfo) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30747' }); + const app = await launchElectronApp('electron-window-app.js', [], { + recordHar: { path: testInfo.outputPath('har.zip') } + }); + const page = await app.firstWindow(); + await page.goto(server.EMPTY_PAGE); + await app.close(); + expect(fs.existsSync(testInfo.outputPath('har.zip'))).toBeTruthy(); + expect(fs.statSync(testInfo.outputPath('har.zip')).size).toBeGreaterThan(0); +}); + test('should be able to get the first window when with a delayed navigation', async ({ launchElectronApp }) => { test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17765' });