Skip to content

Commit

Permalink
fix(electron): record har file (#30748)
Browse files Browse the repository at this point in the history
Fixes #30747
  • Loading branch information
yury-s committed May 10, 2024
1 parent e728e90 commit 64b4ac1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/playwright-core/src/client/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Electron extends ChannelOwner<channels.ElectronChannel> 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;
}
}
Expand All @@ -66,7 +66,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
readonly _context: BrowserContext;
private _windows = new Set<Page>();
private _timeoutSettings = new TimeoutSettings();
private _isClosed = false;

static from(electronApplication: channels.ElectronApplicationChannel): ElectronApplication {
return (electronApplication as any)._object;
Expand All @@ -79,7 +78,6 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
this._onPage(page);
this._context.on(Events.BrowserContext.Page, page => 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)));
Expand Down Expand Up @@ -118,9 +116,7 @@ export class ElectronApplication extends ChannelOwner<channels.ElectronApplicati
}

async close() {
if (this._isClosed)
return;
await this._channel.close().catch(() => {});
await this._context.close().catch(() => {});
}

async waitForEvent(event: string, optionsOrPredicate: WaitForEventOptions = {}): Promise<any> {
Expand Down
2 changes: 0 additions & 2 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 0 additions & 4 deletions packages/protocol/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4124,7 +4124,6 @@ export interface ElectronApplicationChannel extends ElectronApplicationEventTarg
evaluateExpression(params: ElectronApplicationEvaluateExpressionParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionResult>;
evaluateExpressionHandle(params: ElectronApplicationEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<ElectronApplicationEvaluateExpressionHandleResult>;
updateSubscription(params: ElectronApplicationUpdateSubscriptionParams, metadata?: CallMetadata): Promise<ElectronApplicationUpdateSubscriptionResult>;
close(params?: ElectronApplicationCloseParams, metadata?: CallMetadata): Promise<ElectronApplicationCloseResult>;
}
export type ElectronApplicationCloseEvent = {};
export type ElectronApplicationConsoleEvent = {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3243,8 +3243,6 @@ ElectronApplication:
- console
enabled: boolean

close:

events:
close:
console:
Expand Down
12 changes: 12 additions & 0 deletions tests/electron/electron-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down

0 comments on commit 64b4ac1

Please sign in to comment.